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