Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File: pci-acpi.c |
Len Brown | a406d9e | 2005-03-23 16:16:03 -0500 | [diff] [blame] | 3 | * Purpose: Provide PCI support in ACPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
David Shaohua Li | 84df749 | 2005-03-18 18:53:36 -0500 | [diff] [blame] | 5 | * Copyright (C) 2005 David Shaohua Li <shaohua.li@intel.com> |
| 6 | * Copyright (C) 2004 Tom Long Nguyen <tom.l.nguyen@intel.com> |
| 7 | * Copyright (C) 2004 Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/delay.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/pci.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <acpi/acpi.h> |
| 15 | #include <acpi/acnamesp.h> |
| 16 | #include <acpi/acresrc.h> |
| 17 | #include <acpi/acpi_bus.h> |
| 18 | |
| 19 | #include <linux/pci-acpi.h> |
David Shaohua Li | 0f64474 | 2005-03-19 00:15:48 -0500 | [diff] [blame] | 20 | #include "pci.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | static u32 ctrlset_buf[3] = {0, 0, 0}; |
| 23 | static u32 global_ctrlsets = 0; |
Greg KH | bc56b9e | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 24 | static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40, 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | static acpi_status |
| 27 | acpi_query_osc ( |
| 28 | acpi_handle handle, |
| 29 | u32 level, |
| 30 | void *context, |
| 31 | void **retval ) |
| 32 | { |
| 33 | acpi_status status; |
| 34 | struct acpi_object_list input; |
| 35 | union acpi_object in_params[4]; |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 36 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 37 | union acpi_object *out_obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | u32 osc_dw0; |
Kristen Carlson Accardi | 0dcb2b7 | 2006-10-30 13:08:12 -0800 | [diff] [blame] | 39 | acpi_status *ret_status = (acpi_status *)retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | /* Setting up input parameters */ |
| 43 | input.count = 4; |
| 44 | input.pointer = in_params; |
| 45 | in_params[0].type = ACPI_TYPE_BUFFER; |
| 46 | in_params[0].buffer.length = 16; |
| 47 | in_params[0].buffer.pointer = OSC_UUID; |
| 48 | in_params[1].type = ACPI_TYPE_INTEGER; |
| 49 | in_params[1].integer.value = 1; |
| 50 | in_params[2].type = ACPI_TYPE_INTEGER; |
| 51 | in_params[2].integer.value = 3; |
| 52 | in_params[3].type = ACPI_TYPE_BUFFER; |
| 53 | in_params[3].buffer.length = 12; |
| 54 | in_params[3].buffer.pointer = (u8 *)context; |
| 55 | |
| 56 | status = acpi_evaluate_object(handle, "_OSC", &input, &output); |
| 57 | if (ACPI_FAILURE (status)) { |
Kristen Carlson Accardi | 0dcb2b7 | 2006-10-30 13:08:12 -0800 | [diff] [blame] | 58 | *ret_status = status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | return status; |
| 60 | } |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 61 | out_obj = output.pointer; |
| 62 | |
| 63 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | printk(KERN_DEBUG |
| 65 | "Evaluate _OSC returns wrong type\n"); |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 66 | status = AE_TYPE; |
| 67 | goto query_osc_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 69 | osc_dw0 = *((u32 *) out_obj->buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | if (osc_dw0) { |
| 71 | if (osc_dw0 & OSC_REQUEST_ERROR) |
| 72 | printk(KERN_DEBUG "_OSC request fails\n"); |
| 73 | if (osc_dw0 & OSC_INVALID_UUID_ERROR) |
| 74 | printk(KERN_DEBUG "_OSC invalid UUID\n"); |
| 75 | if (osc_dw0 & OSC_INVALID_REVISION_ERROR) |
| 76 | printk(KERN_DEBUG "_OSC invalid revision\n"); |
| 77 | if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) { |
| 78 | /* Update Global Control Set */ |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 79 | global_ctrlsets = *((u32 *)(out_obj->buffer.pointer+8)); |
| 80 | status = AE_OK; |
| 81 | goto query_osc_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 83 | status = AE_ERROR; |
| 84 | goto query_osc_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* Update Global Control Set */ |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 88 | global_ctrlsets = *((u32 *)(out_obj->buffer.pointer + 8)); |
| 89 | status = AE_OK; |
| 90 | |
| 91 | query_osc_out: |
| 92 | kfree(output.pointer); |
Kristen Carlson Accardi | 0dcb2b7 | 2006-10-30 13:08:12 -0800 | [diff] [blame] | 93 | *ret_status = status; |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 94 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | |
| 98 | static acpi_status |
| 99 | acpi_run_osc ( |
| 100 | acpi_handle handle, |
rajesh.shah@intel.com | 427bf53 | 2005-10-31 16:20:11 -0800 | [diff] [blame] | 101 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | acpi_status status; |
| 104 | struct acpi_object_list input; |
| 105 | union acpi_object in_params[4]; |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 106 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 107 | union acpi_object *out_obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | u32 osc_dw0; |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* Setting up input parameters */ |
| 111 | input.count = 4; |
| 112 | input.pointer = in_params; |
| 113 | in_params[0].type = ACPI_TYPE_BUFFER; |
| 114 | in_params[0].buffer.length = 16; |
| 115 | in_params[0].buffer.pointer = OSC_UUID; |
| 116 | in_params[1].type = ACPI_TYPE_INTEGER; |
| 117 | in_params[1].integer.value = 1; |
| 118 | in_params[2].type = ACPI_TYPE_INTEGER; |
| 119 | in_params[2].integer.value = 3; |
| 120 | in_params[3].type = ACPI_TYPE_BUFFER; |
| 121 | in_params[3].buffer.length = 12; |
| 122 | in_params[3].buffer.pointer = (u8 *)context; |
| 123 | |
| 124 | status = acpi_evaluate_object(handle, "_OSC", &input, &output); |
Zhang, Yanmin | 8d29bfb | 2007-06-06 11:44:16 +0800 | [diff] [blame] | 125 | if (ACPI_FAILURE (status)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | return status; |
Zhang, Yanmin | 8d29bfb | 2007-06-06 11:44:16 +0800 | [diff] [blame] | 127 | |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 128 | out_obj = output.pointer; |
| 129 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | printk(KERN_DEBUG |
| 131 | "Evaluate _OSC returns wrong type\n"); |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 132 | status = AE_TYPE; |
| 133 | goto run_osc_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 135 | osc_dw0 = *((u32 *) out_obj->buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | if (osc_dw0) { |
| 137 | if (osc_dw0 & OSC_REQUEST_ERROR) |
| 138 | printk(KERN_DEBUG "_OSC request fails\n"); |
| 139 | if (osc_dw0 & OSC_INVALID_UUID_ERROR) |
| 140 | printk(KERN_DEBUG "_OSC invalid UUID\n"); |
| 141 | if (osc_dw0 & OSC_INVALID_REVISION_ERROR) |
| 142 | printk(KERN_DEBUG "_OSC invalid revision\n"); |
| 143 | if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) { |
| 144 | printk(KERN_DEBUG "_OSC FW not grant req. control\n"); |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 145 | status = AE_SUPPORT; |
| 146 | goto run_osc_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 148 | status = AE_ERROR; |
| 149 | goto run_osc_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
Kristen Accardi | 593ee20 | 2006-05-20 15:00:08 -0700 | [diff] [blame] | 151 | status = AE_OK; |
| 152 | |
| 153 | run_osc_out: |
| 154 | kfree(output.pointer); |
| 155 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /** |
Andrew Patterson | c277835 | 2008-01-22 17:18:12 -0700 | [diff] [blame] | 159 | * __pci_osc_support_set - register OS support to Firmware |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | * @flags: OS support bits |
Randy Dunlap | 5958f1a | 2008-02-03 15:06:25 -0800 | [diff] [blame] | 161 | * @hid: hardware ID |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | * |
| 163 | * Update OS support fields and doing a _OSC Query to obtain an update |
| 164 | * from Firmware on supported control bits. |
| 165 | **/ |
Andrew Patterson | c277835 | 2008-01-22 17:18:12 -0700 | [diff] [blame] | 166 | acpi_status __pci_osc_support_set(u32 flags, const char *hid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
| 168 | u32 temp; |
Kristen Carlson Accardi | 0dcb2b7 | 2006-10-30 13:08:12 -0800 | [diff] [blame] | 169 | acpi_status retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | if (!(flags & OSC_SUPPORT_MASKS)) { |
| 172 | return AE_TYPE; |
| 173 | } |
| 174 | ctrlset_buf[OSC_SUPPORT_TYPE] |= (flags & OSC_SUPPORT_MASKS); |
| 175 | |
| 176 | /* do _OSC query for all possible controls */ |
| 177 | temp = ctrlset_buf[OSC_CONTROL_TYPE]; |
| 178 | ctrlset_buf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; |
| 179 | ctrlset_buf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS; |
Andrew Patterson | c277835 | 2008-01-22 17:18:12 -0700 | [diff] [blame] | 180 | acpi_get_devices(hid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | acpi_query_osc, |
| 182 | ctrlset_buf, |
Kristen Carlson Accardi | 0dcb2b7 | 2006-10-30 13:08:12 -0800 | [diff] [blame] | 183 | (void **) &retval ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | ctrlset_buf[OSC_QUERY_TYPE] = !OSC_QUERY_ENABLE; |
| 185 | ctrlset_buf[OSC_CONTROL_TYPE] = temp; |
Kristen Carlson Accardi | 0dcb2b7 | 2006-10-30 13:08:12 -0800 | [diff] [blame] | 186 | if (ACPI_FAILURE(retval)) { |
| 187 | /* no osc support at all */ |
| 188 | ctrlset_buf[OSC_SUPPORT_TYPE] = 0; |
| 189 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | return AE_OK; |
| 191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | /** |
| 194 | * pci_osc_control_set - commit requested control to Firmware |
Randy Dunlap | f366633 | 2005-11-23 15:45:04 -0800 | [diff] [blame] | 195 | * @handle: acpi_handle for the target ACPI object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * @flags: driver's requested control bits |
| 197 | * |
| 198 | * Attempt to take control from Firmware on requested control bits. |
| 199 | **/ |
rajesh.shah@intel.com | 427bf53 | 2005-10-31 16:20:11 -0800 | [diff] [blame] | 200 | acpi_status pci_osc_control_set(acpi_handle handle, u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
| 202 | acpi_status status; |
| 203 | u32 ctrlset; |
| 204 | |
| 205 | ctrlset = (flags & OSC_CONTROL_MASKS); |
| 206 | if (!ctrlset) { |
| 207 | return AE_TYPE; |
| 208 | } |
| 209 | if (ctrlset_buf[OSC_SUPPORT_TYPE] && |
| 210 | ((global_ctrlsets & ctrlset) != ctrlset)) { |
| 211 | return AE_SUPPORT; |
| 212 | } |
| 213 | ctrlset_buf[OSC_CONTROL_TYPE] |= ctrlset; |
rajesh.shah@intel.com | 427bf53 | 2005-10-31 16:20:11 -0800 | [diff] [blame] | 214 | status = acpi_run_osc(handle, ctrlset_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | if (ACPI_FAILURE (status)) { |
| 216 | ctrlset_buf[OSC_CONTROL_TYPE] &= ~ctrlset; |
| 217 | } |
| 218 | |
| 219 | return status; |
| 220 | } |
| 221 | EXPORT_SYMBOL(pci_osc_control_set); |
David Shaohua Li | 84df749 | 2005-03-18 18:53:36 -0500 | [diff] [blame] | 222 | |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 223 | #ifdef CONFIG_ACPI_SLEEP |
David Shaohua Li | 0f64474 | 2005-03-19 00:15:48 -0500 | [diff] [blame] | 224 | /* |
| 225 | * _SxD returns the D-state with the highest power |
| 226 | * (lowest D-state number) supported in the S-state "x". |
| 227 | * |
| 228 | * If the devices does not have a _PRW |
| 229 | * (Power Resources for Wake) supporting system wakeup from "x" |
| 230 | * then the OS is free to choose a lower power (higher number |
| 231 | * D-state) than the return value from _SxD. |
| 232 | * |
| 233 | * But if _PRW is enabled at S-state "x", the OS |
| 234 | * must not choose a power lower than _SxD -- |
| 235 | * unless the device has an _SxW method specifying |
| 236 | * the lowest power (highest D-state number) the device |
| 237 | * may enter while still able to wake the system. |
| 238 | * |
| 239 | * ie. depending on global OS policy: |
| 240 | * |
| 241 | * if (_PRW at S-state x) |
| 242 | * choose from highest power _SxD to lowest power _SxW |
| 243 | * else // no _PRW at S-state x |
| 244 | * choose highest power _SxD or any lower power |
David Shaohua Li | 0f64474 | 2005-03-19 00:15:48 -0500 | [diff] [blame] | 245 | */ |
| 246 | |
Shaohua Li | ab826ca | 2007-07-20 10:03:22 +0800 | [diff] [blame] | 247 | static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev, |
| 248 | pm_message_t state) |
David Shaohua Li | 0f64474 | 2005-03-19 00:15:48 -0500 | [diff] [blame] | 249 | { |
Shaohua Li | ab826ca | 2007-07-20 10:03:22 +0800 | [diff] [blame] | 250 | int acpi_state; |
David Shaohua Li | 0f64474 | 2005-03-19 00:15:48 -0500 | [diff] [blame] | 251 | |
Shaohua Li | ab826ca | 2007-07-20 10:03:22 +0800 | [diff] [blame] | 252 | acpi_state = acpi_pm_device_sleep_state(&pdev->dev, |
| 253 | device_may_wakeup(&pdev->dev), NULL); |
| 254 | if (acpi_state < 0) |
| 255 | return PCI_POWER_ERROR; |
| 256 | |
| 257 | switch (acpi_state) { |
| 258 | case ACPI_STATE_D0: |
| 259 | return PCI_D0; |
| 260 | case ACPI_STATE_D1: |
| 261 | return PCI_D1; |
| 262 | case ACPI_STATE_D2: |
| 263 | return PCI_D2; |
| 264 | case ACPI_STATE_D3: |
| 265 | return PCI_D3hot; |
| 266 | } |
| 267 | return PCI_POWER_ERROR; |
David Shaohua Li | 0f64474 | 2005-03-19 00:15:48 -0500 | [diff] [blame] | 268 | } |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 269 | #endif |
David Shaohua Li | 0f64474 | 2005-03-19 00:15:48 -0500 | [diff] [blame] | 270 | |
David Shaohua Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 271 | static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) |
| 272 | { |
| 273 | acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev); |
Shaohua Li | 10b3dca | 2007-07-20 10:03:25 +0800 | [diff] [blame] | 274 | acpi_handle tmp; |
David Brownell | 583c377 | 2008-02-22 21:41:51 -0800 | [diff] [blame] | 275 | static const u8 state_conv[] = { |
| 276 | [PCI_D0] = ACPI_STATE_D0, |
| 277 | [PCI_D1] = ACPI_STATE_D1, |
| 278 | [PCI_D2] = ACPI_STATE_D2, |
| 279 | [PCI_D3hot] = ACPI_STATE_D3, |
| 280 | [PCI_D3cold] = ACPI_STATE_D3 |
David Shaohua Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 281 | }; |
David Shaohua Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 282 | |
| 283 | if (!handle) |
| 284 | return -ENODEV; |
Shaohua Li | 10b3dca | 2007-07-20 10:03:25 +0800 | [diff] [blame] | 285 | /* If the ACPI device has _EJ0, ignore the device */ |
| 286 | if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp))) |
| 287 | return 0; |
David Brownell | 583c377 | 2008-02-22 21:41:51 -0800 | [diff] [blame] | 288 | |
| 289 | switch (state) { |
| 290 | case PCI_D0: |
| 291 | case PCI_D1: |
| 292 | case PCI_D2: |
| 293 | case PCI_D3hot: |
| 294 | case PCI_D3cold: |
| 295 | return acpi_bus_set_power(handle, state_conv[state]); |
| 296 | } |
| 297 | return -EINVAL; |
David Shaohua Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | |
David Shaohua Li | 84df749 | 2005-03-18 18:53:36 -0500 | [diff] [blame] | 301 | /* ACPI bus type */ |
Muthu Kumar | 9c273b9 | 2006-04-28 00:42:21 -0700 | [diff] [blame] | 302 | static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) |
David Shaohua Li | 84df749 | 2005-03-18 18:53:36 -0500 | [diff] [blame] | 303 | { |
| 304 | struct pci_dev * pci_dev; |
| 305 | acpi_integer addr; |
| 306 | |
| 307 | pci_dev = to_pci_dev(dev); |
| 308 | /* Please ref to ACPI spec for the syntax of _ADR */ |
| 309 | addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn); |
| 310 | *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr); |
| 311 | if (!*handle) |
| 312 | return -ENODEV; |
| 313 | return 0; |
| 314 | } |
| 315 | |
Muthu Kumar | 9c273b9 | 2006-04-28 00:42:21 -0700 | [diff] [blame] | 316 | static int acpi_pci_find_root_bridge(struct device *dev, acpi_handle *handle) |
David Shaohua Li | 84df749 | 2005-03-18 18:53:36 -0500 | [diff] [blame] | 317 | { |
| 318 | int num; |
| 319 | unsigned int seg, bus; |
| 320 | |
| 321 | /* |
| 322 | * The string should be the same as root bridge's name |
| 323 | * Please look at 'pci_scan_bus_parented' |
| 324 | */ |
| 325 | num = sscanf(dev->bus_id, "pci%04x:%02x", &seg, &bus); |
| 326 | if (num != 2) |
| 327 | return -ENODEV; |
| 328 | *handle = acpi_get_pci_rootbridge_handle(seg, bus); |
| 329 | if (!*handle) |
| 330 | return -ENODEV; |
| 331 | return 0; |
| 332 | } |
| 333 | |
Muthu Kumar | 9c273b9 | 2006-04-28 00:42:21 -0700 | [diff] [blame] | 334 | static struct acpi_bus_type acpi_pci_bus = { |
David Shaohua Li | 84df749 | 2005-03-18 18:53:36 -0500 | [diff] [blame] | 335 | .bus = &pci_bus_type, |
Muthu Kumar | 9c273b9 | 2006-04-28 00:42:21 -0700 | [diff] [blame] | 336 | .find_device = acpi_pci_find_device, |
| 337 | .find_bridge = acpi_pci_find_root_bridge, |
David Shaohua Li | 84df749 | 2005-03-18 18:53:36 -0500 | [diff] [blame] | 338 | }; |
| 339 | |
Muthu Kumar | 9c273b9 | 2006-04-28 00:42:21 -0700 | [diff] [blame] | 340 | static int __init acpi_pci_init(void) |
David Shaohua Li | 84df749 | 2005-03-18 18:53:36 -0500 | [diff] [blame] | 341 | { |
| 342 | int ret; |
| 343 | |
Shaohua Li | f8993af | 2007-04-25 11:05:12 +0800 | [diff] [blame] | 344 | if (acpi_gbl_FADT.boot_flags & BAF_MSI_NOT_SUPPORTED) { |
| 345 | printk(KERN_INFO"ACPI FADT declares the system doesn't support MSI, so disable it\n"); |
| 346 | pci_no_msi(); |
| 347 | } |
Muthu Kumar | 9c273b9 | 2006-04-28 00:42:21 -0700 | [diff] [blame] | 348 | ret = register_acpi_bus_type(&acpi_pci_bus); |
David Shaohua Li | 84df749 | 2005-03-18 18:53:36 -0500 | [diff] [blame] | 349 | if (ret) |
| 350 | return 0; |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 351 | #ifdef CONFIG_ACPI_SLEEP |
David Shaohua Li | 0f64474 | 2005-03-19 00:15:48 -0500 | [diff] [blame] | 352 | platform_pci_choose_state = acpi_pci_choose_state; |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 353 | #endif |
David Shaohua Li | b913100 | 2005-03-19 00:16:18 -0500 | [diff] [blame] | 354 | platform_pci_set_power_state = acpi_pci_set_power_state; |
David Shaohua Li | 84df749 | 2005-03-18 18:53:36 -0500 | [diff] [blame] | 355 | return 0; |
| 356 | } |
Muthu Kumar | 9c273b9 | 2006-04-28 00:42:21 -0700 | [diff] [blame] | 357 | arch_initcall(acpi_pci_init); |