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