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