// SPDX-License-Identifier: GPL-2.0+ /* * PCI HotPlug Controller Core * * Copyright (C) 2001-2002 Greg Kroah-Hartman ([email protected]) * Copyright (C) 2001-2002 IBM Corp. * * All rights reserved. * * Send feedback to <[email protected]> * * Authors: * Greg Kroah-Hartman <[email protected]> * Scott Murray <[email protected]> */ #include <linux/module.h> /* try_module_get & module_put */ #include <linux/moduleparam.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/list.h> #include <linux/kobject.h> #include <linux/sysfs.h> #include <linux/pagemap.h> #include <linux/init.h> #include <linux/mount.h> #include <linux/namei.h> #include <linux/mutex.h> #include <linux/pci.h> #include <linux/pci_hotplug.h> #include <linux/uaccess.h> #include "../pci.h" #include "cpci_hotplug.h" #define MY_NAME … #define dbg(fmt, arg...) … #define err(format, arg...) … #define info(format, arg...) … #define warn(format, arg...) … /* local variables */ static bool debug; static LIST_HEAD(pci_hotplug_slot_list); static DEFINE_MUTEX(pci_hp_mutex); /* Weee, fun with macros... */ #define GET_STATUS(name, type) … GET_STATUS(…) GET_STATUS(…) GET_STATUS(…) GET_STATUS(…) static ssize_t power_read_file(struct pci_slot *pci_slot, char *buf) { … } static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf, size_t count) { … } static struct pci_slot_attribute hotplug_slot_attr_power = …; static ssize_t attention_read_file(struct pci_slot *pci_slot, char *buf) { … } static ssize_t attention_write_file(struct pci_slot *pci_slot, const char *buf, size_t count) { … } static struct pci_slot_attribute hotplug_slot_attr_attention = …; static ssize_t latch_read_file(struct pci_slot *pci_slot, char *buf) { … } static struct pci_slot_attribute hotplug_slot_attr_latch = …; static ssize_t presence_read_file(struct pci_slot *pci_slot, char *buf) { … } static struct pci_slot_attribute hotplug_slot_attr_presence = …; static ssize_t test_write_file(struct pci_slot *pci_slot, const char *buf, size_t count) { … } static struct pci_slot_attribute hotplug_slot_attr_test = …; static bool has_power_file(struct pci_slot *pci_slot) { … } static bool has_attention_file(struct pci_slot *pci_slot) { … } static bool has_latch_file(struct pci_slot *pci_slot) { … } static bool has_adapter_file(struct pci_slot *pci_slot) { … } static bool has_test_file(struct pci_slot *pci_slot) { … } static int fs_add_slot(struct pci_slot *pci_slot) { … } static void fs_remove_slot(struct pci_slot *pci_slot) { … } static struct hotplug_slot *get_slot_from_name(const char *name) { … } /** * __pci_hp_register - register a hotplug_slot with the PCI hotplug subsystem * @bus: bus this slot is on * @slot: pointer to the &struct hotplug_slot to register * @devnr: device number * @name: name registered with kobject core * @owner: caller module owner * @mod_name: caller module name * * Prepares a hotplug slot for in-kernel use and immediately publishes it to * user space in one go. Drivers may alternatively carry out the two steps * separately by invoking pci_hp_initialize() and pci_hp_add(). * * Returns 0 if successful, anything else for an error. */ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int devnr, const char *name, struct module *owner, const char *mod_name) { … } EXPORT_SYMBOL_GPL(…); /** * __pci_hp_initialize - prepare hotplug slot for in-kernel use * @slot: pointer to the &struct hotplug_slot to initialize * @bus: bus this slot is on * @devnr: slot number * @name: name registered with kobject core * @owner: caller module owner * @mod_name: caller module name * * Allocate and fill in a PCI slot for use by a hotplug driver. Once this has * been called, the driver may invoke hotplug_slot_name() to get the slot's * unique name. The driver must be prepared to handle a ->reset_slot callback * from this point on. * * Returns 0 on success or a negative int on error. */ int __pci_hp_initialize(struct hotplug_slot *slot, struct pci_bus *bus, int devnr, const char *name, struct module *owner, const char *mod_name) { … } EXPORT_SYMBOL_GPL(…); /** * pci_hp_add - publish hotplug slot to user space * @slot: pointer to the &struct hotplug_slot to publish * * Make a hotplug slot's sysfs interface available and inform user space of its * addition by sending a uevent. The hotplug driver must be prepared to handle * all &struct hotplug_slot_ops callbacks from this point on. * * Returns 0 on success or a negative int on error. */ int pci_hp_add(struct hotplug_slot *slot) { … } EXPORT_SYMBOL_GPL(…); /** * pci_hp_deregister - deregister a hotplug_slot with the PCI hotplug subsystem * @slot: pointer to the &struct hotplug_slot to deregister * * The @slot must have been registered with the pci hotplug subsystem * previously with a call to pci_hp_register(). * * Returns 0 if successful, anything else for an error. */ void pci_hp_deregister(struct hotplug_slot *slot) { … } EXPORT_SYMBOL_GPL(…); /** * pci_hp_del - unpublish hotplug slot from user space * @slot: pointer to the &struct hotplug_slot to unpublish * * Remove a hotplug slot's sysfs interface. * * Returns 0 on success or a negative int on error. */ void pci_hp_del(struct hotplug_slot *slot) { … } EXPORT_SYMBOL_GPL(…); /** * pci_hp_destroy - remove hotplug slot from in-kernel use * @slot: pointer to the &struct hotplug_slot to destroy * * Destroy a PCI slot used by a hotplug driver. Once this has been called, * the driver may no longer invoke hotplug_slot_name() to get the slot's * unique name. The driver no longer needs to handle a ->reset_slot callback * from this point on. * * Returns 0 on success or a negative int on error. */ void pci_hp_destroy(struct hotplug_slot *slot) { … } EXPORT_SYMBOL_GPL(…); static int __init pci_hotplug_init(void) { … } device_initcall(pci_hotplug_init); /* * not really modular, but the easiest way to keep compat with existing * bootargs behaviour is to continue using module_param here. */ module_param(debug, bool, 0644); MODULE_PARM_DESC(…) …;