mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-17 09:14:19 +08:00
125450f814
When the PCI hotplug core and its first user, cpqphp, were introduced in February 2002 with historic commit a8a2069f432c, cpqphp allocated a slot struct for its internal use plus a hotplug_slot struct to be registered with the hotplug core and linked the two with pointers: https://git.kernel.org/tglx/history/c/a8a2069f432c Nowadays, the predominant pattern in the tree is to embed ("subclass") such structures in one another and cast to the containing struct with container_of(). But it wasn't until July 2002 that container_of() was introduced with historic commit ec4f214232cf: https://git.kernel.org/tglx/history/c/ec4f214232cf pnv_php, introduced in 2016, did the right thing and embedded struct hotplug_slot in its internal struct pnv_php_slot, but all other drivers cargo-culted cpqphp's design and linked separate structs with pointers. Embedding structs is preferrable to linking them with pointers because it requires fewer allocations, thereby reducing overhead and simplifying error paths. Casting an embedded struct to the containing struct becomes a cheap subtraction rather than a dereference. And having fewer pointers reduces the risk of them pointing nowhere either accidentally or due to an attack. Convert all drivers to embed struct hotplug_slot in their internal slot struct. The "private" pointer in struct hotplug_slot thereby becomes unused, so drop it. Signed-off-by: Lukas Wunner <lukas@wunner.de> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com> # drivers/pci/hotplug/rpa* Acked-by: Sebastian Ott <sebott@linux.ibm.com> # drivers/pci/hotplug/s390* Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86 Cc: Len Brown <lenb@kernel.org> Cc: Scott Murray <scott@spiteful.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Oliver OHalloran <oliveroh@au1.ibm.com> Cc: Gavin Shan <gwshan@linux.vnet.ibm.com> Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com> Cc: Corentin Chary <corentin.chary@gmail.com> Cc: Darren Hart <dvhart@infradead.org>
100 lines
2.4 KiB
C
100 lines
2.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
/*
|
|
* PCI Hot Plug Controller Driver for RPA-compliant PPC64 platform.
|
|
*
|
|
* Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
|
|
*
|
|
* All rights reserved.
|
|
*
|
|
* Send feedback to <lxie@us.ibm.com>,
|
|
*
|
|
*/
|
|
|
|
#ifndef _PPC64PHP_H
|
|
#define _PPC64PHP_H
|
|
|
|
#include <linux/pci.h>
|
|
#include <linux/pci_hotplug.h>
|
|
|
|
#define DR_INDICATOR 9002
|
|
#define DR_ENTITY_SENSE 9003
|
|
|
|
#define POWER_ON 100
|
|
#define POWER_OFF 0
|
|
|
|
#define LED_OFF 0
|
|
#define LED_ON 1 /* continuous on */
|
|
#define LED_ID 2 /* slow blinking */
|
|
#define LED_ACTION 3 /* fast blinking */
|
|
|
|
/* Sensor values from rtas_get-sensor */
|
|
#define EMPTY 0 /* No card in slot */
|
|
#define PRESENT 1 /* Card in slot */
|
|
|
|
#define MY_NAME "rpaphp"
|
|
extern bool rpaphp_debug;
|
|
#define dbg(format, arg...) \
|
|
do { \
|
|
if (rpaphp_debug) \
|
|
printk(KERN_DEBUG "%s: " format, \
|
|
MY_NAME, ## arg); \
|
|
} while (0)
|
|
#define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME, ## arg)
|
|
#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME, ## arg)
|
|
#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME, ## arg)
|
|
|
|
/* slot states */
|
|
|
|
#define NOT_VALID 3
|
|
#define NOT_CONFIGURED 2
|
|
#define CONFIGURED 1
|
|
#define EMPTY 0
|
|
|
|
/* DRC constants */
|
|
|
|
#define MAX_DRC_NAME_LEN 64
|
|
|
|
/*
|
|
* struct slot - slot information for each *physical* slot
|
|
*/
|
|
struct slot {
|
|
struct list_head rpaphp_slot_list;
|
|
int state;
|
|
u32 index;
|
|
u32 type;
|
|
u32 power_domain;
|
|
u8 attention_status;
|
|
char *name;
|
|
struct device_node *dn;
|
|
struct pci_bus *bus;
|
|
struct list_head *pci_devs;
|
|
struct hotplug_slot hotplug_slot;
|
|
};
|
|
|
|
extern const struct hotplug_slot_ops rpaphp_hotplug_slot_ops;
|
|
extern struct list_head rpaphp_slot_head;
|
|
|
|
static inline struct slot *to_slot(struct hotplug_slot *hotplug_slot)
|
|
{
|
|
return container_of(hotplug_slot, struct slot, hotplug_slot);
|
|
}
|
|
|
|
/* function prototypes */
|
|
|
|
/* rpaphp_pci.c */
|
|
int rpaphp_enable_slot(struct slot *slot);
|
|
int rpaphp_get_sensor_state(struct slot *slot, int *state);
|
|
|
|
/* rpaphp_core.c */
|
|
int rpaphp_add_slot(struct device_node *dn);
|
|
int rpaphp_check_drc_props(struct device_node *dn, char *drc_name,
|
|
char *drc_type);
|
|
|
|
/* rpaphp_slot.c */
|
|
void dealloc_slot_struct(struct slot *slot);
|
|
struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_name, int power_domain);
|
|
int rpaphp_register_slot(struct slot *slot);
|
|
int rpaphp_deregister_slot(struct slot *slot);
|
|
|
|
#endif /* _PPC64PHP_H */
|