xref: /OK3568_Linux_fs/kernel/drivers/pci/slot.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (C) 2006 Matthew Wilcox <matthew@wil.cx>
4*4882a593Smuzhiyun  * Copyright (C) 2006-2009 Hewlett-Packard Development Company, L.P.
5*4882a593Smuzhiyun  *	Alex Chiang <achiang@hp.com>
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #include <linux/kobject.h>
9*4882a593Smuzhiyun #include <linux/slab.h>
10*4882a593Smuzhiyun #include <linux/module.h>
11*4882a593Smuzhiyun #include <linux/pci.h>
12*4882a593Smuzhiyun #include <linux/err.h>
13*4882a593Smuzhiyun #include "pci.h"
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun struct kset *pci_slots_kset;
16*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pci_slots_kset);
17*4882a593Smuzhiyun 
pci_slot_attr_show(struct kobject * kobj,struct attribute * attr,char * buf)18*4882a593Smuzhiyun static ssize_t pci_slot_attr_show(struct kobject *kobj,
19*4882a593Smuzhiyun 					struct attribute *attr, char *buf)
20*4882a593Smuzhiyun {
21*4882a593Smuzhiyun 	struct pci_slot *slot = to_pci_slot(kobj);
22*4882a593Smuzhiyun 	struct pci_slot_attribute *attribute = to_pci_slot_attr(attr);
23*4882a593Smuzhiyun 	return attribute->show ? attribute->show(slot, buf) : -EIO;
24*4882a593Smuzhiyun }
25*4882a593Smuzhiyun 
pci_slot_attr_store(struct kobject * kobj,struct attribute * attr,const char * buf,size_t len)26*4882a593Smuzhiyun static ssize_t pci_slot_attr_store(struct kobject *kobj,
27*4882a593Smuzhiyun 			struct attribute *attr, const char *buf, size_t len)
28*4882a593Smuzhiyun {
29*4882a593Smuzhiyun 	struct pci_slot *slot = to_pci_slot(kobj);
30*4882a593Smuzhiyun 	struct pci_slot_attribute *attribute = to_pci_slot_attr(attr);
31*4882a593Smuzhiyun 	return attribute->store ? attribute->store(slot, buf, len) : -EIO;
32*4882a593Smuzhiyun }
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun static const struct sysfs_ops pci_slot_sysfs_ops = {
35*4882a593Smuzhiyun 	.show = pci_slot_attr_show,
36*4882a593Smuzhiyun 	.store = pci_slot_attr_store,
37*4882a593Smuzhiyun };
38*4882a593Smuzhiyun 
address_read_file(struct pci_slot * slot,char * buf)39*4882a593Smuzhiyun static ssize_t address_read_file(struct pci_slot *slot, char *buf)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun 	if (slot->number == 0xff)
42*4882a593Smuzhiyun 		return sprintf(buf, "%04x:%02x\n",
43*4882a593Smuzhiyun 				pci_domain_nr(slot->bus),
44*4882a593Smuzhiyun 				slot->bus->number);
45*4882a593Smuzhiyun 	else
46*4882a593Smuzhiyun 		return sprintf(buf, "%04x:%02x:%02x\n",
47*4882a593Smuzhiyun 				pci_domain_nr(slot->bus),
48*4882a593Smuzhiyun 				slot->bus->number,
49*4882a593Smuzhiyun 				slot->number);
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun 
bus_speed_read(enum pci_bus_speed speed,char * buf)52*4882a593Smuzhiyun static ssize_t bus_speed_read(enum pci_bus_speed speed, char *buf)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun 	return sprintf(buf, "%s\n", pci_speed_string(speed));
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun 
max_speed_read_file(struct pci_slot * slot,char * buf)57*4882a593Smuzhiyun static ssize_t max_speed_read_file(struct pci_slot *slot, char *buf)
58*4882a593Smuzhiyun {
59*4882a593Smuzhiyun 	return bus_speed_read(slot->bus->max_bus_speed, buf);
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun 
cur_speed_read_file(struct pci_slot * slot,char * buf)62*4882a593Smuzhiyun static ssize_t cur_speed_read_file(struct pci_slot *slot, char *buf)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun 	return bus_speed_read(slot->bus->cur_bus_speed, buf);
65*4882a593Smuzhiyun }
66*4882a593Smuzhiyun 
pci_slot_release(struct kobject * kobj)67*4882a593Smuzhiyun static void pci_slot_release(struct kobject *kobj)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun 	struct pci_dev *dev;
70*4882a593Smuzhiyun 	struct pci_slot *slot = to_pci_slot(kobj);
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	dev_dbg(&slot->bus->dev, "dev %02x, released physical slot %s\n",
73*4882a593Smuzhiyun 		slot->number, pci_slot_name(slot));
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	down_read(&pci_bus_sem);
76*4882a593Smuzhiyun 	list_for_each_entry(dev, &slot->bus->devices, bus_list)
77*4882a593Smuzhiyun 		if (PCI_SLOT(dev->devfn) == slot->number)
78*4882a593Smuzhiyun 			dev->slot = NULL;
79*4882a593Smuzhiyun 	up_read(&pci_bus_sem);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	list_del(&slot->list);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	kfree(slot);
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun static struct pci_slot_attribute pci_slot_attr_address =
87*4882a593Smuzhiyun 	__ATTR(address, S_IRUGO, address_read_file, NULL);
88*4882a593Smuzhiyun static struct pci_slot_attribute pci_slot_attr_max_speed =
89*4882a593Smuzhiyun 	__ATTR(max_bus_speed, S_IRUGO, max_speed_read_file, NULL);
90*4882a593Smuzhiyun static struct pci_slot_attribute pci_slot_attr_cur_speed =
91*4882a593Smuzhiyun 	__ATTR(cur_bus_speed, S_IRUGO, cur_speed_read_file, NULL);
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun static struct attribute *pci_slot_default_attrs[] = {
94*4882a593Smuzhiyun 	&pci_slot_attr_address.attr,
95*4882a593Smuzhiyun 	&pci_slot_attr_max_speed.attr,
96*4882a593Smuzhiyun 	&pci_slot_attr_cur_speed.attr,
97*4882a593Smuzhiyun 	NULL,
98*4882a593Smuzhiyun };
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun static struct kobj_type pci_slot_ktype = {
101*4882a593Smuzhiyun 	.sysfs_ops = &pci_slot_sysfs_ops,
102*4882a593Smuzhiyun 	.release = &pci_slot_release,
103*4882a593Smuzhiyun 	.default_attrs = pci_slot_default_attrs,
104*4882a593Smuzhiyun };
105*4882a593Smuzhiyun 
make_slot_name(const char * name)106*4882a593Smuzhiyun static char *make_slot_name(const char *name)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun 	char *new_name;
109*4882a593Smuzhiyun 	int len, max, dup;
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 	new_name = kstrdup(name, GFP_KERNEL);
112*4882a593Smuzhiyun 	if (!new_name)
113*4882a593Smuzhiyun 		return NULL;
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	/*
116*4882a593Smuzhiyun 	 * Make sure we hit the realloc case the first time through the
117*4882a593Smuzhiyun 	 * loop.  'len' will be strlen(name) + 3 at that point which is
118*4882a593Smuzhiyun 	 * enough space for "name-X" and the trailing NUL.
119*4882a593Smuzhiyun 	 */
120*4882a593Smuzhiyun 	len = strlen(name) + 2;
121*4882a593Smuzhiyun 	max = 1;
122*4882a593Smuzhiyun 	dup = 1;
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	for (;;) {
125*4882a593Smuzhiyun 		struct kobject *dup_slot;
126*4882a593Smuzhiyun 		dup_slot = kset_find_obj(pci_slots_kset, new_name);
127*4882a593Smuzhiyun 		if (!dup_slot)
128*4882a593Smuzhiyun 			break;
129*4882a593Smuzhiyun 		kobject_put(dup_slot);
130*4882a593Smuzhiyun 		if (dup == max) {
131*4882a593Smuzhiyun 			len++;
132*4882a593Smuzhiyun 			max *= 10;
133*4882a593Smuzhiyun 			kfree(new_name);
134*4882a593Smuzhiyun 			new_name = kmalloc(len, GFP_KERNEL);
135*4882a593Smuzhiyun 			if (!new_name)
136*4882a593Smuzhiyun 				break;
137*4882a593Smuzhiyun 		}
138*4882a593Smuzhiyun 		sprintf(new_name, "%s-%d", name, dup++);
139*4882a593Smuzhiyun 	}
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	return new_name;
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun 
rename_slot(struct pci_slot * slot,const char * name)144*4882a593Smuzhiyun static int rename_slot(struct pci_slot *slot, const char *name)
145*4882a593Smuzhiyun {
146*4882a593Smuzhiyun 	int result = 0;
147*4882a593Smuzhiyun 	char *slot_name;
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun 	if (strcmp(pci_slot_name(slot), name) == 0)
150*4882a593Smuzhiyun 		return result;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	slot_name = make_slot_name(name);
153*4882a593Smuzhiyun 	if (!slot_name)
154*4882a593Smuzhiyun 		return -ENOMEM;
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun 	result = kobject_rename(&slot->kobj, slot_name);
157*4882a593Smuzhiyun 	kfree(slot_name);
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	return result;
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun 
pci_dev_assign_slot(struct pci_dev * dev)162*4882a593Smuzhiyun void pci_dev_assign_slot(struct pci_dev *dev)
163*4882a593Smuzhiyun {
164*4882a593Smuzhiyun 	struct pci_slot *slot;
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	mutex_lock(&pci_slot_mutex);
167*4882a593Smuzhiyun 	list_for_each_entry(slot, &dev->bus->slots, list)
168*4882a593Smuzhiyun 		if (PCI_SLOT(dev->devfn) == slot->number)
169*4882a593Smuzhiyun 			dev->slot = slot;
170*4882a593Smuzhiyun 	mutex_unlock(&pci_slot_mutex);
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun 
get_slot(struct pci_bus * parent,int slot_nr)173*4882a593Smuzhiyun static struct pci_slot *get_slot(struct pci_bus *parent, int slot_nr)
174*4882a593Smuzhiyun {
175*4882a593Smuzhiyun 	struct pci_slot *slot;
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun 	/* We already hold pci_slot_mutex */
178*4882a593Smuzhiyun 	list_for_each_entry(slot, &parent->slots, list)
179*4882a593Smuzhiyun 		if (slot->number == slot_nr) {
180*4882a593Smuzhiyun 			kobject_get(&slot->kobj);
181*4882a593Smuzhiyun 			return slot;
182*4882a593Smuzhiyun 		}
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun 	return NULL;
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun /**
188*4882a593Smuzhiyun  * pci_create_slot - create or increment refcount for physical PCI slot
189*4882a593Smuzhiyun  * @parent: struct pci_bus of parent bridge
190*4882a593Smuzhiyun  * @slot_nr: PCI_SLOT(pci_dev->devfn) or -1 for placeholder
191*4882a593Smuzhiyun  * @name: user visible string presented in /sys/bus/pci/slots/<name>
192*4882a593Smuzhiyun  * @hotplug: set if caller is hotplug driver, NULL otherwise
193*4882a593Smuzhiyun  *
194*4882a593Smuzhiyun  * PCI slots have first class attributes such as address, speed, width,
195*4882a593Smuzhiyun  * and a &struct pci_slot is used to manage them. This interface will
196*4882a593Smuzhiyun  * either return a new &struct pci_slot to the caller, or if the pci_slot
197*4882a593Smuzhiyun  * already exists, its refcount will be incremented.
198*4882a593Smuzhiyun  *
199*4882a593Smuzhiyun  * Slots are uniquely identified by a @pci_bus, @slot_nr tuple.
200*4882a593Smuzhiyun  *
201*4882a593Smuzhiyun  * There are known platforms with broken firmware that assign the same
202*4882a593Smuzhiyun  * name to multiple slots. Workaround these broken platforms by renaming
203*4882a593Smuzhiyun  * the slots on behalf of the caller. If firmware assigns name N to
204*4882a593Smuzhiyun  * multiple slots:
205*4882a593Smuzhiyun  *
206*4882a593Smuzhiyun  * The first slot is assigned N
207*4882a593Smuzhiyun  * The second slot is assigned N-1
208*4882a593Smuzhiyun  * The third slot is assigned N-2
209*4882a593Smuzhiyun  * etc.
210*4882a593Smuzhiyun  *
211*4882a593Smuzhiyun  * Placeholder slots:
212*4882a593Smuzhiyun  * In most cases, @pci_bus, @slot_nr will be sufficient to uniquely identify
213*4882a593Smuzhiyun  * a slot. There is one notable exception - pSeries (rpaphp), where the
214*4882a593Smuzhiyun  * @slot_nr cannot be determined until a device is actually inserted into
215*4882a593Smuzhiyun  * the slot. In this scenario, the caller may pass -1 for @slot_nr.
216*4882a593Smuzhiyun  *
217*4882a593Smuzhiyun  * The following semantics are imposed when the caller passes @slot_nr ==
218*4882a593Smuzhiyun  * -1. First, we no longer check for an existing %struct pci_slot, as there
219*4882a593Smuzhiyun  * may be many slots with @slot_nr of -1.  The other change in semantics is
220*4882a593Smuzhiyun  * user-visible, which is the 'address' parameter presented in sysfs will
221*4882a593Smuzhiyun  * consist solely of a dddd:bb tuple, where dddd is the PCI domain of the
222*4882a593Smuzhiyun  * %struct pci_bus and bb is the bus number. In other words, the devfn of
223*4882a593Smuzhiyun  * the 'placeholder' slot will not be displayed.
224*4882a593Smuzhiyun  */
pci_create_slot(struct pci_bus * parent,int slot_nr,const char * name,struct hotplug_slot * hotplug)225*4882a593Smuzhiyun struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
226*4882a593Smuzhiyun 				 const char *name,
227*4882a593Smuzhiyun 				 struct hotplug_slot *hotplug)
228*4882a593Smuzhiyun {
229*4882a593Smuzhiyun 	struct pci_dev *dev;
230*4882a593Smuzhiyun 	struct pci_slot *slot;
231*4882a593Smuzhiyun 	int err = 0;
232*4882a593Smuzhiyun 	char *slot_name = NULL;
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun 	mutex_lock(&pci_slot_mutex);
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun 	if (slot_nr == -1)
237*4882a593Smuzhiyun 		goto placeholder;
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 	/*
240*4882a593Smuzhiyun 	 * Hotplug drivers are allowed to rename an existing slot,
241*4882a593Smuzhiyun 	 * but only if not already claimed.
242*4882a593Smuzhiyun 	 */
243*4882a593Smuzhiyun 	slot = get_slot(parent, slot_nr);
244*4882a593Smuzhiyun 	if (slot) {
245*4882a593Smuzhiyun 		if (hotplug) {
246*4882a593Smuzhiyun 			if ((err = slot->hotplug ? -EBUSY : 0)
247*4882a593Smuzhiyun 			     || (err = rename_slot(slot, name))) {
248*4882a593Smuzhiyun 				kobject_put(&slot->kobj);
249*4882a593Smuzhiyun 				slot = NULL;
250*4882a593Smuzhiyun 				goto err;
251*4882a593Smuzhiyun 			}
252*4882a593Smuzhiyun 		}
253*4882a593Smuzhiyun 		goto out;
254*4882a593Smuzhiyun 	}
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun placeholder:
257*4882a593Smuzhiyun 	slot = kzalloc(sizeof(*slot), GFP_KERNEL);
258*4882a593Smuzhiyun 	if (!slot) {
259*4882a593Smuzhiyun 		err = -ENOMEM;
260*4882a593Smuzhiyun 		goto err;
261*4882a593Smuzhiyun 	}
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 	slot->bus = parent;
264*4882a593Smuzhiyun 	slot->number = slot_nr;
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun 	slot->kobj.kset = pci_slots_kset;
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun 	slot_name = make_slot_name(name);
269*4882a593Smuzhiyun 	if (!slot_name) {
270*4882a593Smuzhiyun 		err = -ENOMEM;
271*4882a593Smuzhiyun 		kfree(slot);
272*4882a593Smuzhiyun 		goto err;
273*4882a593Smuzhiyun 	}
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun 	INIT_LIST_HEAD(&slot->list);
276*4882a593Smuzhiyun 	list_add(&slot->list, &parent->slots);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun 	err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL,
279*4882a593Smuzhiyun 				   "%s", slot_name);
280*4882a593Smuzhiyun 	if (err) {
281*4882a593Smuzhiyun 		kobject_put(&slot->kobj);
282*4882a593Smuzhiyun 		goto err;
283*4882a593Smuzhiyun 	}
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun 	down_read(&pci_bus_sem);
286*4882a593Smuzhiyun 	list_for_each_entry(dev, &parent->devices, bus_list)
287*4882a593Smuzhiyun 		if (PCI_SLOT(dev->devfn) == slot_nr)
288*4882a593Smuzhiyun 			dev->slot = slot;
289*4882a593Smuzhiyun 	up_read(&pci_bus_sem);
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun 	dev_dbg(&parent->dev, "dev %02x, created physical slot %s\n",
292*4882a593Smuzhiyun 		slot_nr, pci_slot_name(slot));
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun out:
295*4882a593Smuzhiyun 	kfree(slot_name);
296*4882a593Smuzhiyun 	mutex_unlock(&pci_slot_mutex);
297*4882a593Smuzhiyun 	return slot;
298*4882a593Smuzhiyun err:
299*4882a593Smuzhiyun 	slot = ERR_PTR(err);
300*4882a593Smuzhiyun 	goto out;
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pci_create_slot);
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun /**
305*4882a593Smuzhiyun  * pci_destroy_slot - decrement refcount for physical PCI slot
306*4882a593Smuzhiyun  * @slot: struct pci_slot to decrement
307*4882a593Smuzhiyun  *
308*4882a593Smuzhiyun  * %struct pci_slot is refcounted, so destroying them is really easy; we
309*4882a593Smuzhiyun  * just call kobject_put on its kobj and let our release methods do the
310*4882a593Smuzhiyun  * rest.
311*4882a593Smuzhiyun  */
pci_destroy_slot(struct pci_slot * slot)312*4882a593Smuzhiyun void pci_destroy_slot(struct pci_slot *slot)
313*4882a593Smuzhiyun {
314*4882a593Smuzhiyun 	dev_dbg(&slot->bus->dev, "dev %02x, dec refcount to %d\n",
315*4882a593Smuzhiyun 		slot->number, kref_read(&slot->kobj.kref) - 1);
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun 	mutex_lock(&pci_slot_mutex);
318*4882a593Smuzhiyun 	kobject_put(&slot->kobj);
319*4882a593Smuzhiyun 	mutex_unlock(&pci_slot_mutex);
320*4882a593Smuzhiyun }
321*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pci_destroy_slot);
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
324*4882a593Smuzhiyun #include <linux/pci_hotplug.h>
325*4882a593Smuzhiyun /**
326*4882a593Smuzhiyun  * pci_hp_create_link - create symbolic link to the hotplug driver module.
327*4882a593Smuzhiyun  * @pci_slot: struct pci_slot
328*4882a593Smuzhiyun  *
329*4882a593Smuzhiyun  * Helper function for pci_hotplug_core.c to create symbolic link to
330*4882a593Smuzhiyun  * the hotplug driver module.
331*4882a593Smuzhiyun  */
pci_hp_create_module_link(struct pci_slot * pci_slot)332*4882a593Smuzhiyun void pci_hp_create_module_link(struct pci_slot *pci_slot)
333*4882a593Smuzhiyun {
334*4882a593Smuzhiyun 	struct hotplug_slot *slot = pci_slot->hotplug;
335*4882a593Smuzhiyun 	struct kobject *kobj = NULL;
336*4882a593Smuzhiyun 	int ret;
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun 	if (!slot || !slot->ops)
339*4882a593Smuzhiyun 		return;
340*4882a593Smuzhiyun 	kobj = kset_find_obj(module_kset, slot->mod_name);
341*4882a593Smuzhiyun 	if (!kobj)
342*4882a593Smuzhiyun 		return;
343*4882a593Smuzhiyun 	ret = sysfs_create_link(&pci_slot->kobj, kobj, "module");
344*4882a593Smuzhiyun 	if (ret)
345*4882a593Smuzhiyun 		dev_err(&pci_slot->bus->dev, "Error creating sysfs link (%d)\n",
346*4882a593Smuzhiyun 			ret);
347*4882a593Smuzhiyun 	kobject_put(kobj);
348*4882a593Smuzhiyun }
349*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pci_hp_create_module_link);
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun /**
352*4882a593Smuzhiyun  * pci_hp_remove_link - remove symbolic link to the hotplug driver module.
353*4882a593Smuzhiyun  * @pci_slot: struct pci_slot
354*4882a593Smuzhiyun  *
355*4882a593Smuzhiyun  * Helper function for pci_hotplug_core.c to remove symbolic link to
356*4882a593Smuzhiyun  * the hotplug driver module.
357*4882a593Smuzhiyun  */
pci_hp_remove_module_link(struct pci_slot * pci_slot)358*4882a593Smuzhiyun void pci_hp_remove_module_link(struct pci_slot *pci_slot)
359*4882a593Smuzhiyun {
360*4882a593Smuzhiyun 	sysfs_remove_link(&pci_slot->kobj, "module");
361*4882a593Smuzhiyun }
362*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pci_hp_remove_module_link);
363*4882a593Smuzhiyun #endif
364*4882a593Smuzhiyun 
pci_slot_init(void)365*4882a593Smuzhiyun static int pci_slot_init(void)
366*4882a593Smuzhiyun {
367*4882a593Smuzhiyun 	struct kset *pci_bus_kset;
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun 	pci_bus_kset = bus_get_kset(&pci_bus_type);
370*4882a593Smuzhiyun 	pci_slots_kset = kset_create_and_add("slots", NULL,
371*4882a593Smuzhiyun 						&pci_bus_kset->kobj);
372*4882a593Smuzhiyun 	if (!pci_slots_kset) {
373*4882a593Smuzhiyun 		pr_err("PCI: Slot initialization failure\n");
374*4882a593Smuzhiyun 		return -ENOMEM;
375*4882a593Smuzhiyun 	}
376*4882a593Smuzhiyun 	return 0;
377*4882a593Smuzhiyun }
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun subsys_initcall(pci_slot_init);
380