43 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/pci.h>
50 #include <linux/slab.h>
58 #define MY_NAME "acpiphp_glue"
60 static void handle_hotplug_event_bridge (
acpi_handle,
u32,
void *);
61 static void acpiphp_sanitize_bus(
struct pci_bus *
bus);
62 static void acpiphp_set_hpp_values(
struct pci_bus *
bus);
69 int *
count = (
int *)context;
99 pci_read_config_dword(bus->
self,
103 if (((buses >> 8) & 0xff) != bus->
busn_res.start) {
104 buses = (buses & 0xff000000)
105 | ((
unsigned int)(bus->
primary) << 0)
107 | ((
unsigned int)(bus->
busn_res.end) << 16);
115 .handler = handle_hotplug_event_func,
119 static bool device_is_managed_by_native_pciehp(
struct pci_dev *pdev)
123 struct acpi_pci_root *
root;
135 tmp = acpi_find_root_bridge_handle(pdev);
141 if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
149 register_slot(
acpi_handle handle,
u32 lvl,
void *context,
void **rv)
156 unsigned long long adr, sun;
166 warn(
"can't evaluate _ADR (%#x)\n", status);
170 device = (adr >> 16) & 0xffff;
171 function = adr & 0xffff;
174 if (pdev && device_is_managed_by_native_pciehp(pdev))
181 INIT_LIST_HEAD(&newfunc->
sibling);
210 for (slot = bridge->
slots; slot; slot = slot->
next)
211 if (slot->
device == device) {
212 if (slot->
sun != sun)
213 warn(
"sibling found, but _SUN doesn't match!\n");
227 INIT_LIST_HEAD(&slot->
funcs);
235 dbg(
"found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
239 if (retval == -
EBUSY)
240 warn(
"Slot %llu already registered by another "
241 "hotplug driver\n", slot->
sun);
243 warn(
"acpiphp_register_hotplug_slot failed "
244 "(err code = 0x%x)\n", retval);
265 &acpiphp_dock_ops, newfunc))
266 dbg(
"failed to register dock device\n");
272 newfunc->
nb.notifier_call = post_dock_fixups;
274 dbg(
"failed to register a dock notifier");
281 handle_hotplug_event_func,
285 err(
"failed to register interrupt notify handler\n");
302 static int detect_ejectable_slots(
acpi_handle handle)
307 is_pci_dock_device,
NULL, (
void *)&found,
NULL);
318 list_add(&bridge->
list, &bridge_list);
333 handle_hotplug_event_func);
335 err(
"failed to remove notify handler\n");
339 handle_hotplug_event_bridge,
343 err(
"failed to register interrupt notify handler\n");
357 for (slot = bridge->
slots; slot; slot = slot->
next) {
359 if (func->
handle == handle)
369 static inline void config_p2p_bridge_flags(
struct acpiphp_bridge *bridge)
374 "_STA", &dummy_handle)))
378 "_EJ0", &dummy_handle)))
382 "_PS0", &dummy_handle)))
386 "_PS3", &dummy_handle)))
393 dbg(
"found ejectable p2p bridge\n");
396 func = acpiphp_bridge_handle_to_function(bridge->
handle);
406 static void add_host_bridge(
struct acpi_pci_root *root)
420 init_bridge_misc(bridge);
430 if (bridge ==
NULL) {
431 err(
"out of memory\n");
437 config_p2p_bridge_flags(bridge);
442 err(
"This is not a PCI-to-PCI bridge!\n");
453 init_bridge_misc(bridge);
464 find_p2p_bridge(
acpi_handle handle,
u32 lvl,
void *context,
void **rv)
474 if ((detect_ejectable_slots(handle) > 0)) {
475 dbg(
"found PCI-to-PCI bridge at PCI %s\n", pci_name(dev));
476 add_p2p_bridge(handle);
483 warn(
"find_p2p_bridge failed (error code = 0x%x)\n", status);
492 static int add_bridge(
struct acpi_pci_root *root)
495 unsigned long long tmp;
504 dbg(
"%s: _STA evaluation failure\n", __func__);
513 if (detect_ejectable_slots(handle) > 0) {
514 dbg(
"found PCI host-bus bridge with hot-pluggable slots\n");
515 add_host_bridge(root);
523 warn(
"find_p2p_bridge failed (error code = 0x%x)\n", status);
533 if (bridge->handle == handle)
547 handle_hotplug_event_bridge);
549 err(
"failed to remove notify handler\n");
555 handle_hotplug_event_func,
558 err(
"failed to install interrupt notify handler\n");
561 slot = bridge->slots;
572 handle_hotplug_event_func);
574 err(
"failed to remove notify handler\n");
597 cleanup_p2p_bridge(
acpi_handle handle,
u32 lvl,
void *context,
void **rv)
604 cleanup_p2p_bridge, NULL, NULL, NULL);
606 bridge = acpiphp_handle_to_bridge(handle);
608 cleanup_bridge(bridge);
613 static void remove_bridge(
struct acpi_pci_root *root)
621 (
u32)1, cleanup_p2p_bridge, NULL, NULL, NULL);
630 bridge = acpiphp_handle_to_bridge(handle);
632 cleanup_bridge(bridge);
635 handle_hotplug_event_bridge);
650 dbg(
"%s: executing _PS0\n", __func__);
653 warn(
"%s: _PS0 failed\n", __func__);
685 warn(
"%s: _PS3 failed\n", __func__);
707 static unsigned char acpiphp_max_busnr(
struct pci_bus *bus)
710 unsigned char max,
n;
738 struct acpi_device *device, *pdevice;
743 dbg(
"no parent device, assuming NULL\n");
747 dbg(
"bus exists... trim\n");
752 dbg(
"acpi_bus_trim return %x\n", ret_val);
756 ACPI_BUS_TYPE_DEVICE);
758 dbg(
"error adding bus, %x\n",
760 goto acpiphp_bus_add_out;
775 struct acpi_device *device;
780 dbg(
"acpi_device not found\n");
786 err(
"cannot remove from acpi list\n");
791 static void acpiphp_set_acpi_region(
struct acpiphp_slot *slot)
799 arg_list.pointer =
params;
803 params[1].integer.value = 1;
831 dbg(
"No new device found\n");
835 max = acpiphp_max_busnr(bus);
836 for (pass = 0; pass < 2; pass++) {
850 acpiphp_bus_add(func);
853 acpiphp_sanitize_bus(bus);
854 acpiphp_set_hpp_values(bus);
855 acpiphp_set_acpi_region(slot);
861 dev->current_state =
PCI_D0;
883 status = find_p2p_bridge(func->handle, (
u32)1, bus, NULL);
885 warn(
"find_p2p_bridge failed (error code = 0x%x)\n",
933 cleanup_p2p_bridge(func->
bridge->handle,
945 while ((pdev = dev_in_slot(slot))) {
951 acpiphp_bus_trim(func->
handle);
973 static unsigned int get_slot_status(
struct acpiphp_slot *slot)
976 unsigned long long sta = 0;
986 pci_bus_read_config_dword(slot->
bridge->pci_bus,
990 if (dvid != 0xffffffff) {
997 return (
unsigned int)sta;
1022 warn(
"%s: _EJ0 failed\n", __func__);
1044 enabled = disabled = 0;
1046 for (slot = bridge->
slots; slot; slot = slot->
next) {
1047 unsigned int status = get_slot_status(slot);
1053 err(
"Error occurred in disabling\n");
1064 err(
"Error occurred in enabling\n");
1071 dbg(
"%s: %d enabled, %d disabled\n", __func__, enabled, disabled);
1077 static void acpiphp_set_hpp_values(
struct pci_bus *bus)
1098 if ((res->
flags & type_mask) && !res->
start &&
1110 static int acpiphp_configure_bridge (
acpi_handle handle)
1125 acpiphp_sanitize_bus(bus);
1126 acpiphp_set_hpp_values(bus);
1133 struct acpi_device *device, *pdevice;
1138 err(
"unexpected notification type %d\n", type);
1144 dbg(
"no parent device, assuming NULL\n");
1147 if (
acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE)) {
1148 err(
"cannot add bridge to acpi list\n");
1151 if (!acpiphp_configure_bridge(handle) &&
1155 err(
"cannot configure and start bridge\n");
1164 count_sub_bridges(
acpi_handle handle,
u32 lvl,
void *context,
void **rv)
1166 int *count = (
int *)context;
1169 bridge = acpiphp_handle_to_bridge(handle);
1176 check_sub_bridges(
acpi_handle handle,
u32 lvl,
void *context,
void **rv)
1183 bridge = acpiphp_handle_to_bridge(handle);
1186 dbg(
"%s: re-enumerating slots under %s\n",
1188 acpiphp_check_bridge(bridge);
1227 struct acpi_device *device;
1228 int num_sub_bridges = 0;
1234 handle = hp_work->
handle;
1235 type = hp_work->
type;
1239 handle_bridge_insertion(handle, type);
1243 bridge = acpiphp_handle_to_bridge(handle);
1246 count_sub_bridges, NULL, &num_sub_bridges, NULL);
1249 if (!bridge && !num_sub_bridges) {
1250 err(
"cannot get bridge info\n");
1259 dbg(
"%s: Bus check notify on %s\n", __func__, objname);
1261 dbg(
"%s: re-enumerating slots under %s\n",
1263 acpiphp_check_bridge(bridge);
1265 if (num_sub_bridges)
1272 dbg(
"%s: Device check notify on %s\n", __func__, objname);
1273 acpiphp_check_bridge(bridge);
1278 dbg(
"%s: Device wake notify on %s\n", __func__, objname);
1283 dbg(
"%s: Device eject notify on %s\n", __func__, objname);
1287 slot = bridge->
func->slot;
1295 " to a frequency mismatch\n", objname);
1300 " to a bus mode mismatch\n", objname);
1309 warn(
"notify_handler: unknown event type 0x%x for %s\n", type, objname);
1325 static void handle_hotplug_event_bridge(
acpi_handle handle,
u32 type,
1336 alloc_acpiphp_hp_work(handle, type, context,
1337 _handle_hotplug_event_bridge);
1340 static void _handle_hotplug_event_func(
struct work_struct *work)
1352 handle = hp_work->
handle;
1353 type = hp_work->
type;
1363 dbg(
"%s: Bus check notify on %s\n", __func__, objname);
1369 dbg(
"%s: Device check notify on %s\n", __func__, objname);
1370 acpiphp_check_bridge(func->
slot->bridge);
1375 dbg(
"%s: Device wake notify on %s\n", __func__, objname);
1380 dbg(
"%s: Device eject notify on %s\n", __func__, objname);
1386 warn(
"notify_handler: unknown event type 0x%x for %s\n", type, objname);
1401 static void handle_hotplug_event_func(
acpi_handle handle,
u32 type,
1412 alloc_acpiphp_hp_work(handle, type, context,
1413 _handle_hotplug_event_func);
1417 find_root_bridges(
acpi_handle handle,
u32 lvl,
void *context,
void **rv)
1419 int *count = (
int *)context;
1426 handle_hotplug_event_bridge, NULL);
1431 static struct acpi_pci_driver acpi_pci_hp_driver = {
1433 .remove = remove_bridge,
1475 dbg(
"Bus %04x:%02x has %d slot%s\n",
1482 dbg(
"Total %d slots\n", num_slots);
1498 retval = power_on_slot(slot);
1504 retval = enable_device(slot);
1506 power_off_slot(slot);
1508 dbg(
"%s: Slot status is not ACPI_STA_ALL\n", __func__);
1509 power_off_slot(slot);
1528 retval = disable_device(slot);
1533 retval = power_off_slot(slot);
1561 sta = get_slot_status(slot);
1575 sta = get_slot_status(slot);
1577 return (sta == 0) ? 0 : 1;