Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Common ACPI functions for hot plug platforms |
| 3 | * |
| 4 | * Copyright (C) 2006 Intel Corporation |
| 5 | * |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or (at |
| 11 | * your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 16 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 17 | * details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | * |
| 23 | * Send feedback to <kristen.c.accardi@intel.com> |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include <linux/module.h> |
Kenji Kaneshige | aad20ca | 2006-05-10 22:20:34 +0900 | [diff] [blame] | 28 | #include <linux/moduleparam.h> |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 29 | #include <linux/kernel.h> |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/pci.h> |
Greg Kroah-Hartman | 7a54f25 | 2006-10-13 20:05:19 -0700 | [diff] [blame] | 32 | #include <linux/pci_hotplug.h> |
Kenji Kaneshige | 9f5404d | 2009-02-09 16:00:04 +0900 | [diff] [blame] | 33 | #include <linux/acpi.h> |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 34 | #include <linux/pci-acpi.h> |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 35 | |
Kenji Kaneshige | aad20ca | 2006-05-10 22:20:34 +0900 | [diff] [blame] | 36 | #define MY_NAME "acpi_pcihp" |
| 37 | |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 38 | #define dbg(fmt, arg...) do { if (debug_acpi) printk(KERN_DEBUG "%s: %s: " fmt , MY_NAME , __func__ , ## arg); } while (0) |
Kenji Kaneshige | aad20ca | 2006-05-10 22:20:34 +0900 | [diff] [blame] | 39 | #define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg) |
| 40 | #define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg) |
| 41 | #define warn(format, arg...) printk(KERN_WARNING "%s: " format , MY_NAME , ## arg) |
| 42 | |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 43 | #define METHOD_NAME__SUN "_SUN" |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 44 | #define METHOD_NAME_OSHP "OSHP" |
| 45 | |
Kenji Kaneshige | aad20ca | 2006-05-10 22:20:34 +0900 | [diff] [blame] | 46 | static int debug_acpi; |
| 47 | |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 48 | static acpi_status |
| 49 | decode_type0_hpx_record(union acpi_object *record, struct hotplug_params *hpx) |
| 50 | { |
| 51 | int i; |
| 52 | union acpi_object *fields = record->package.elements; |
| 53 | u32 revision = fields[1].integer.value; |
| 54 | |
| 55 | switch (revision) { |
| 56 | case 1: |
| 57 | if (record->package.count != 6) |
| 58 | return AE_ERROR; |
| 59 | for (i = 2; i < 6; i++) |
| 60 | if (fields[i].type != ACPI_TYPE_INTEGER) |
| 61 | return AE_ERROR; |
| 62 | hpx->t0 = &hpx->type0_data; |
| 63 | hpx->t0->revision = revision; |
| 64 | hpx->t0->cache_line_size = fields[2].integer.value; |
| 65 | hpx->t0->latency_timer = fields[3].integer.value; |
| 66 | hpx->t0->enable_serr = fields[4].integer.value; |
| 67 | hpx->t0->enable_perr = fields[5].integer.value; |
| 68 | break; |
| 69 | default: |
| 70 | printk(KERN_WARNING |
| 71 | "%s: Type 0 Revision %d record not supported\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 72 | __func__, revision); |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 73 | return AE_ERROR; |
| 74 | } |
| 75 | return AE_OK; |
| 76 | } |
| 77 | |
| 78 | static acpi_status |
| 79 | decode_type1_hpx_record(union acpi_object *record, struct hotplug_params *hpx) |
| 80 | { |
| 81 | int i; |
| 82 | union acpi_object *fields = record->package.elements; |
| 83 | u32 revision = fields[1].integer.value; |
| 84 | |
| 85 | switch (revision) { |
| 86 | case 1: |
| 87 | if (record->package.count != 5) |
| 88 | return AE_ERROR; |
| 89 | for (i = 2; i < 5; i++) |
| 90 | if (fields[i].type != ACPI_TYPE_INTEGER) |
| 91 | return AE_ERROR; |
| 92 | hpx->t1 = &hpx->type1_data; |
| 93 | hpx->t1->revision = revision; |
| 94 | hpx->t1->max_mem_read = fields[2].integer.value; |
| 95 | hpx->t1->avg_max_split = fields[3].integer.value; |
| 96 | hpx->t1->tot_max_split = fields[4].integer.value; |
| 97 | break; |
| 98 | default: |
| 99 | printk(KERN_WARNING |
| 100 | "%s: Type 1 Revision %d record not supported\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 101 | __func__, revision); |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 102 | return AE_ERROR; |
| 103 | } |
| 104 | return AE_OK; |
| 105 | } |
| 106 | |
| 107 | static acpi_status |
| 108 | decode_type2_hpx_record(union acpi_object *record, struct hotplug_params *hpx) |
| 109 | { |
| 110 | int i; |
| 111 | union acpi_object *fields = record->package.elements; |
| 112 | u32 revision = fields[1].integer.value; |
| 113 | |
| 114 | switch (revision) { |
| 115 | case 1: |
| 116 | if (record->package.count != 18) |
| 117 | return AE_ERROR; |
| 118 | for (i = 2; i < 18; i++) |
| 119 | if (fields[i].type != ACPI_TYPE_INTEGER) |
| 120 | return AE_ERROR; |
| 121 | hpx->t2 = &hpx->type2_data; |
| 122 | hpx->t2->revision = revision; |
| 123 | hpx->t2->unc_err_mask_and = fields[2].integer.value; |
| 124 | hpx->t2->unc_err_mask_or = fields[3].integer.value; |
| 125 | hpx->t2->unc_err_sever_and = fields[4].integer.value; |
| 126 | hpx->t2->unc_err_sever_or = fields[5].integer.value; |
| 127 | hpx->t2->cor_err_mask_and = fields[6].integer.value; |
| 128 | hpx->t2->cor_err_mask_or = fields[7].integer.value; |
| 129 | hpx->t2->adv_err_cap_and = fields[8].integer.value; |
| 130 | hpx->t2->adv_err_cap_or = fields[9].integer.value; |
| 131 | hpx->t2->pci_exp_devctl_and = fields[10].integer.value; |
| 132 | hpx->t2->pci_exp_devctl_or = fields[11].integer.value; |
| 133 | hpx->t2->pci_exp_lnkctl_and = fields[12].integer.value; |
| 134 | hpx->t2->pci_exp_lnkctl_or = fields[13].integer.value; |
| 135 | hpx->t2->sec_unc_err_sever_and = fields[14].integer.value; |
| 136 | hpx->t2->sec_unc_err_sever_or = fields[15].integer.value; |
| 137 | hpx->t2->sec_unc_err_mask_and = fields[16].integer.value; |
| 138 | hpx->t2->sec_unc_err_mask_or = fields[17].integer.value; |
| 139 | break; |
| 140 | default: |
| 141 | printk(KERN_WARNING |
| 142 | "%s: Type 2 Revision %d record not supported\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 143 | __func__, revision); |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 144 | return AE_ERROR; |
| 145 | } |
| 146 | return AE_OK; |
| 147 | } |
| 148 | |
| 149 | static acpi_status |
| 150 | acpi_run_hpx(acpi_handle handle, struct hotplug_params *hpx) |
| 151 | { |
| 152 | acpi_status status; |
| 153 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 154 | union acpi_object *package, *record, *fields; |
| 155 | u32 type; |
| 156 | int i; |
| 157 | |
| 158 | /* Clear the return buffer with zeros */ |
| 159 | memset(hpx, 0, sizeof(struct hotplug_params)); |
| 160 | |
| 161 | status = acpi_evaluate_object(handle, "_HPX", NULL, &buffer); |
| 162 | if (ACPI_FAILURE(status)) |
| 163 | return status; |
| 164 | |
| 165 | package = (union acpi_object *)buffer.pointer; |
| 166 | if (package->type != ACPI_TYPE_PACKAGE) { |
| 167 | status = AE_ERROR; |
| 168 | goto exit; |
| 169 | } |
| 170 | |
| 171 | for (i = 0; i < package->package.count; i++) { |
| 172 | record = &package->package.elements[i]; |
| 173 | if (record->type != ACPI_TYPE_PACKAGE) { |
| 174 | status = AE_ERROR; |
| 175 | goto exit; |
| 176 | } |
| 177 | |
| 178 | fields = record->package.elements; |
| 179 | if (fields[0].type != ACPI_TYPE_INTEGER || |
| 180 | fields[1].type != ACPI_TYPE_INTEGER) { |
| 181 | status = AE_ERROR; |
| 182 | goto exit; |
| 183 | } |
| 184 | |
| 185 | type = fields[0].integer.value; |
| 186 | switch (type) { |
| 187 | case 0: |
| 188 | status = decode_type0_hpx_record(record, hpx); |
| 189 | if (ACPI_FAILURE(status)) |
| 190 | goto exit; |
| 191 | break; |
| 192 | case 1: |
| 193 | status = decode_type1_hpx_record(record, hpx); |
| 194 | if (ACPI_FAILURE(status)) |
| 195 | goto exit; |
| 196 | break; |
| 197 | case 2: |
| 198 | status = decode_type2_hpx_record(record, hpx); |
| 199 | if (ACPI_FAILURE(status)) |
| 200 | goto exit; |
| 201 | break; |
| 202 | default: |
| 203 | printk(KERN_ERR "%s: Type %d record not supported\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 204 | __func__, type); |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 205 | status = AE_ERROR; |
| 206 | goto exit; |
| 207 | } |
| 208 | } |
| 209 | exit: |
| 210 | kfree(buffer.pointer); |
| 211 | return status; |
| 212 | } |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 213 | |
| 214 | static acpi_status |
| 215 | acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp) |
| 216 | { |
Bjorn Helgaas | 5e3573d | 2009-09-14 16:35:40 -0600 | [diff] [blame] | 217 | acpi_status status; |
| 218 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 219 | union acpi_object *package, *fields; |
| 220 | int i; |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 221 | |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 222 | memset(hpp, 0, sizeof(struct hotplug_params)); |
| 223 | |
Bjorn Helgaas | 5e3573d | 2009-09-14 16:35:40 -0600 | [diff] [blame] | 224 | status = acpi_evaluate_object(handle, "_HPP", NULL, &buffer); |
| 225 | if (ACPI_FAILURE(status)) |
| 226 | return status; |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 227 | |
Bjorn Helgaas | 5e3573d | 2009-09-14 16:35:40 -0600 | [diff] [blame] | 228 | package = (union acpi_object *) buffer.pointer; |
| 229 | if (package->type != ACPI_TYPE_PACKAGE || |
| 230 | package->package.count != 4) { |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 231 | status = AE_ERROR; |
Bjorn Helgaas | 5e3573d | 2009-09-14 16:35:40 -0600 | [diff] [blame] | 232 | goto exit; |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Bjorn Helgaas | 5e3573d | 2009-09-14 16:35:40 -0600 | [diff] [blame] | 235 | fields = package->package.elements; |
| 236 | for (i = 0; i < 4; i++) { |
| 237 | if (fields[i].type != ACPI_TYPE_INTEGER) { |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 238 | status = AE_ERROR; |
Bjorn Helgaas | 5e3573d | 2009-09-14 16:35:40 -0600 | [diff] [blame] | 239 | goto exit; |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 243 | hpp->t0 = &hpp->type0_data; |
Bjorn Helgaas | 5e3573d | 2009-09-14 16:35:40 -0600 | [diff] [blame] | 244 | hpp->t0->revision = 1; |
| 245 | hpp->t0->cache_line_size = fields[0].integer.value; |
| 246 | hpp->t0->latency_timer = fields[1].integer.value; |
| 247 | hpp->t0->enable_serr = fields[2].integer.value; |
| 248 | hpp->t0->enable_perr = fields[3].integer.value; |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 249 | |
Bjorn Helgaas | 5e3573d | 2009-09-14 16:35:40 -0600 | [diff] [blame] | 250 | exit: |
| 251 | kfree(buffer.pointer); |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 252 | return status; |
| 253 | } |
| 254 | |
| 255 | |
| 256 | |
| 257 | /* acpi_run_oshp - get control of hotplug from the firmware |
| 258 | * |
| 259 | * @handle - the handle of the hotplug controller. |
| 260 | */ |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 261 | static acpi_status acpi_run_oshp(acpi_handle handle) |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 262 | { |
| 263 | acpi_status status; |
MUNEDA Takahiro | b2e6e3b | 2006-03-17 09:18:39 +0900 | [diff] [blame] | 264 | struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 265 | |
| 266 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &string); |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 267 | |
| 268 | /* run OSHP */ |
| 269 | status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL); |
| 270 | if (ACPI_FAILURE(status)) |
Kenji Kaneshige | aad20ca | 2006-05-10 22:20:34 +0900 | [diff] [blame] | 271 | if (status != AE_NOT_FOUND) |
| 272 | printk(KERN_ERR "%s:%s OSHP fails=0x%x\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 273 | __func__, (char *)string.pointer, status); |
Kenji Kaneshige | aad20ca | 2006-05-10 22:20:34 +0900 | [diff] [blame] | 274 | else |
| 275 | dbg("%s:%s OSHP not found\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 276 | __func__, (char *)string.pointer); |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 277 | else |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 278 | pr_debug("%s:%s OSHP passes\n", __func__, |
MUNEDA Takahiro | b2e6e3b | 2006-03-17 09:18:39 +0900 | [diff] [blame] | 279 | (char *)string.pointer); |
| 280 | |
Kristen Accardi | 81b26bc | 2006-04-18 14:36:43 -0700 | [diff] [blame] | 281 | kfree(string.pointer); |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 282 | return status; |
| 283 | } |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 284 | |
Bjorn Helgaas | e81995b | 2009-09-14 16:35:35 -0600 | [diff] [blame] | 285 | /* pci_get_hp_params |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 286 | * |
Bjorn Helgaas | 6a29172 | 2009-09-14 16:35:15 -0600 | [diff] [blame] | 287 | * @dev - the pci_dev for which we want parameters |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 288 | * @hpp - allocated by the caller |
| 289 | */ |
Bjorn Helgaas | e81995b | 2009-09-14 16:35:35 -0600 | [diff] [blame] | 290 | int pci_get_hp_params(struct pci_dev *dev, struct hotplug_params *hpp) |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 291 | { |
Bjorn Helgaas | 6a29172 | 2009-09-14 16:35:15 -0600 | [diff] [blame] | 292 | acpi_status status; |
Kenji Kaneshige | 7430e34 | 2006-05-02 10:54:50 +0900 | [diff] [blame] | 293 | acpi_handle handle, phandle; |
Kenji Kaneshige | 267efd7 | 2009-02-17 14:13:20 +0900 | [diff] [blame] | 294 | struct pci_bus *pbus; |
Kenji Kaneshige | 7430e34 | 2006-05-02 10:54:50 +0900 | [diff] [blame] | 295 | |
Kenji Kaneshige | 267efd7 | 2009-02-17 14:13:20 +0900 | [diff] [blame] | 296 | handle = NULL; |
Bjorn Helgaas | 6a29172 | 2009-09-14 16:35:15 -0600 | [diff] [blame] | 297 | for (pbus = dev->bus; pbus; pbus = pbus->parent) { |
Kenji Kaneshige | 267efd7 | 2009-02-17 14:13:20 +0900 | [diff] [blame] | 298 | handle = acpi_pci_get_bridge_handle(pbus); |
| 299 | if (handle) |
Kenji Kaneshige | 7430e34 | 2006-05-02 10:54:50 +0900 | [diff] [blame] | 300 | break; |
Kenji Kaneshige | 267efd7 | 2009-02-17 14:13:20 +0900 | [diff] [blame] | 301 | } |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 302 | |
| 303 | /* |
| 304 | * _HPP settings apply to all child buses, until another _HPP is |
| 305 | * encountered. If we don't find an _HPP for the input pci dev, |
| 306 | * look for it in the parent device scope since that would apply to |
Bjorn Helgaas | e81995b | 2009-09-14 16:35:35 -0600 | [diff] [blame] | 307 | * this pci dev. |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 308 | */ |
Kenji Kaneshige | 7430e34 | 2006-05-02 10:54:50 +0900 | [diff] [blame] | 309 | while (handle) { |
Kenji Kaneshige | e22b7350 | 2006-05-02 10:57:14 +0900 | [diff] [blame] | 310 | status = acpi_run_hpx(handle, hpp); |
| 311 | if (ACPI_SUCCESS(status)) |
Bjorn Helgaas | 6a29172 | 2009-09-14 16:35:15 -0600 | [diff] [blame] | 312 | return 0; |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 313 | status = acpi_run_hpp(handle, hpp); |
Kenji Kaneshige | 7430e34 | 2006-05-02 10:54:50 +0900 | [diff] [blame] | 314 | if (ACPI_SUCCESS(status)) |
Bjorn Helgaas | 6a29172 | 2009-09-14 16:35:15 -0600 | [diff] [blame] | 315 | return 0; |
Alexander Chiang | 2755820 | 2009-06-10 19:55:14 +0000 | [diff] [blame] | 316 | if (acpi_is_root_bridge(handle)) |
Kenji Kaneshige | 7430e34 | 2006-05-02 10:54:50 +0900 | [diff] [blame] | 317 | break; |
| 318 | status = acpi_get_parent(handle, &phandle); |
| 319 | if (ACPI_FAILURE(status)) |
| 320 | break; |
| 321 | handle = phandle; |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 322 | } |
Bjorn Helgaas | 6a29172 | 2009-09-14 16:35:15 -0600 | [diff] [blame] | 323 | return -ENODEV; |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 324 | } |
Bjorn Helgaas | e81995b | 2009-09-14 16:35:35 -0600 | [diff] [blame] | 325 | EXPORT_SYMBOL_GPL(pci_get_hp_params); |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 326 | |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 327 | /** |
| 328 | * acpi_get_hp_hw_control_from_firmware |
| 329 | * @dev: the pci_dev of the bridge that has a hotplug controller |
| 330 | * @flags: requested control bits for _OSC |
| 331 | * |
| 332 | * Attempt to take hotplug control from firmware. |
| 333 | */ |
Kenji Kaneshige | d391f00 | 2009-02-17 14:13:59 +0900 | [diff] [blame] | 334 | int acpi_get_hp_hw_control_from_firmware(struct pci_dev *pdev, u32 flags) |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 335 | { |
| 336 | acpi_status status; |
Jiri Slaby | e0d94be | 2008-08-11 17:47:40 +0200 | [diff] [blame] | 337 | acpi_handle chandle, handle; |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 338 | struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 339 | |
| 340 | flags &= (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL | |
| 341 | OSC_SHPC_NATIVE_HP_CONTROL | |
| 342 | OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); |
| 343 | if (!flags) { |
| 344 | err("Invalid flags %u specified!\n", flags); |
| 345 | return -EINVAL; |
| 346 | } |
| 347 | |
| 348 | /* |
| 349 | * Per PCI firmware specification, we should run the ACPI _OSC |
| 350 | * method to get control of hotplug hardware before using it. If |
| 351 | * an _OSC is missing, we look for an OSHP to do the same thing. |
Jiri Slaby | e0d94be | 2008-08-11 17:47:40 +0200 | [diff] [blame] | 352 | * To handle different BIOS behavior, we look for _OSC on a root |
| 353 | * bridge preferentially (according to PCI fw spec). Later for |
| 354 | * OSHP within the scope of the hotplug controller and its parents, |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 355 | * upto the host bridge under which this controller exists. |
| 356 | */ |
Jiri Slaby | 056c58e | 2008-08-18 20:22:54 +0200 | [diff] [blame] | 357 | handle = acpi_find_root_bridge_handle(pdev); |
Jiri Slaby | e0d94be | 2008-08-11 17:47:40 +0200 | [diff] [blame] | 358 | if (handle) { |
| 359 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &string); |
| 360 | dbg("Trying to get hotplug control for %s\n", |
| 361 | (char *)string.pointer); |
Kenji Kaneshige | 9f5404d | 2009-02-09 16:00:04 +0900 | [diff] [blame] | 362 | status = acpi_pci_osc_control_set(handle, flags); |
Jiri Slaby | e0d94be | 2008-08-11 17:47:40 +0200 | [diff] [blame] | 363 | if (ACPI_SUCCESS(status)) |
| 364 | goto got_one; |
| 365 | kfree(string.pointer); |
| 366 | string = (struct acpi_buffer){ ACPI_ALLOCATE_BUFFER, NULL }; |
| 367 | } |
| 368 | |
Kenji Kaneshige | d391f00 | 2009-02-17 14:13:59 +0900 | [diff] [blame] | 369 | handle = DEVICE_ACPI_HANDLE(&pdev->dev); |
| 370 | if (!handle) { |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 371 | /* |
| 372 | * This hotplug controller was not listed in the ACPI name |
| 373 | * space at all. Try to get acpi handle of parent pci bus. |
| 374 | */ |
Kenji Kaneshige | d391f00 | 2009-02-17 14:13:59 +0900 | [diff] [blame] | 375 | struct pci_bus *pbus; |
| 376 | for (pbus = pdev->bus; pbus; pbus = pbus->parent) { |
| 377 | handle = acpi_pci_get_bridge_handle(pbus); |
| 378 | if (handle) |
| 379 | break; |
| 380 | } |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | while (handle) { |
| 384 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &string); |
| 385 | dbg("Trying to get hotplug control for %s \n", |
| 386 | (char *)string.pointer); |
Jiri Slaby | e0d94be | 2008-08-11 17:47:40 +0200 | [diff] [blame] | 387 | status = acpi_run_oshp(handle); |
| 388 | if (ACPI_SUCCESS(status)) |
| 389 | goto got_one; |
Alexander Chiang | 2755820 | 2009-06-10 19:55:14 +0000 | [diff] [blame] | 390 | if (acpi_is_root_bridge(handle)) |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 391 | break; |
| 392 | chandle = handle; |
| 393 | status = acpi_get_parent(chandle, &handle); |
| 394 | if (ACPI_FAILURE(status)) |
| 395 | break; |
| 396 | } |
| 397 | |
| 398 | dbg("Cannot get control of hotplug hardware for pci %s\n", |
Kenji Kaneshige | d391f00 | 2009-02-17 14:13:59 +0900 | [diff] [blame] | 399 | pci_name(pdev)); |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 400 | |
| 401 | kfree(string.pointer); |
| 402 | return -ENODEV; |
Jiri Slaby | e0d94be | 2008-08-11 17:47:40 +0200 | [diff] [blame] | 403 | got_one: |
Kenji Kaneshige | d391f00 | 2009-02-17 14:13:59 +0900 | [diff] [blame] | 404 | dbg("Gained control for hotplug HW for pci %s (%s)\n", |
| 405 | pci_name(pdev), (char *)string.pointer); |
Jiri Slaby | e0d94be | 2008-08-11 17:47:40 +0200 | [diff] [blame] | 406 | kfree(string.pointer); |
| 407 | return 0; |
Kenji Kaneshige | ac9c052 | 2008-05-28 15:01:03 +0900 | [diff] [blame] | 408 | } |
| 409 | EXPORT_SYMBOL(acpi_get_hp_hw_control_from_firmware); |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 410 | |
Kenji Kaneshige | e8c331e | 2008-12-17 12:09:12 +0900 | [diff] [blame] | 411 | static int is_ejectable(acpi_handle handle) |
| 412 | { |
| 413 | acpi_status status; |
| 414 | acpi_handle tmp; |
| 415 | unsigned long long removable; |
| 416 | status = acpi_get_handle(handle, "_ADR", &tmp); |
| 417 | if (ACPI_FAILURE(status)) |
| 418 | return 0; |
| 419 | status = acpi_get_handle(handle, "_EJ0", &tmp); |
| 420 | if (ACPI_SUCCESS(status)) |
| 421 | return 1; |
| 422 | status = acpi_evaluate_integer(handle, "_RMV", NULL, &removable); |
| 423 | if (ACPI_SUCCESS(status) && removable) |
| 424 | return 1; |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * acpi_pcihp_check_ejectable - check if handle is ejectable ACPI PCI slot |
| 430 | * @pbus: the PCI bus of the PCI slot corresponding to 'handle' |
| 431 | * @handle: ACPI handle to check |
| 432 | * |
| 433 | * Return 1 if handle is ejectable PCI slot, 0 otherwise. |
| 434 | */ |
| 435 | int acpi_pci_check_ejectable(struct pci_bus *pbus, acpi_handle handle) |
| 436 | { |
| 437 | acpi_handle bridge_handle, parent_handle; |
| 438 | |
| 439 | if (!(bridge_handle = acpi_pci_get_bridge_handle(pbus))) |
| 440 | return 0; |
| 441 | if ((ACPI_FAILURE(acpi_get_parent(handle, &parent_handle)))) |
| 442 | return 0; |
| 443 | if (bridge_handle != parent_handle) |
| 444 | return 0; |
| 445 | return is_ejectable(handle); |
| 446 | } |
| 447 | EXPORT_SYMBOL_GPL(acpi_pci_check_ejectable); |
| 448 | |
| 449 | static acpi_status |
| 450 | check_hotplug(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 451 | { |
| 452 | int *found = (int *)context; |
| 453 | if (is_ejectable(handle)) { |
| 454 | *found = 1; |
| 455 | return AE_CTRL_TERMINATE; |
| 456 | } |
| 457 | return AE_OK; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * acpi_pci_detect_ejectable - check if the PCI bus has ejectable slots |
Alex Chiang | 7f53866 | 2009-09-10 12:34:09 -0600 | [diff] [blame] | 462 | * @handle - handle of the PCI bus to scan |
Kenji Kaneshige | e8c331e | 2008-12-17 12:09:12 +0900 | [diff] [blame] | 463 | * |
| 464 | * Returns 1 if the PCI bus has ACPI based ejectable slots, 0 otherwise. |
| 465 | */ |
Alex Chiang | 7f53866 | 2009-09-10 12:34:09 -0600 | [diff] [blame] | 466 | int acpi_pci_detect_ejectable(acpi_handle handle) |
Kenji Kaneshige | e8c331e | 2008-12-17 12:09:12 +0900 | [diff] [blame] | 467 | { |
Kenji Kaneshige | e8c331e | 2008-12-17 12:09:12 +0900 | [diff] [blame] | 468 | int found = 0; |
| 469 | |
Alex Chiang | 7f53866 | 2009-09-10 12:34:09 -0600 | [diff] [blame] | 470 | if (!handle) |
| 471 | return found; |
| 472 | |
| 473 | acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1, |
Kenji Kaneshige | e8c331e | 2008-12-17 12:09:12 +0900 | [diff] [blame] | 474 | check_hotplug, (void *)&found, NULL); |
| 475 | return found; |
| 476 | } |
| 477 | EXPORT_SYMBOL_GPL(acpi_pci_detect_ejectable); |
| 478 | |
Kenji Kaneshige | aad20ca | 2006-05-10 22:20:34 +0900 | [diff] [blame] | 479 | module_param(debug_acpi, bool, 0644); |
| 480 | MODULE_PARM_DESC(debug_acpi, "Debugging mode for ACPI enabled or not"); |