Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PCIEHPRM ACPI: PHP Resource Manager for ACPI platform |
| 3 | * |
| 4 | * Copyright (C) 2003-2004 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 | * |
Kristen Accardi | 8cf4c19 | 2005-08-16 15:16:10 -0700 | [diff] [blame] | 23 | * Send feedback to <kristen.c.accardi@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * |
| 25 | */ |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/pci-acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <acpi/acpi_bus.h> |
| 34 | #include <acpi/actypes.h> |
| 35 | #include "pciehp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #define METHOD_NAME__SUN "_SUN" |
| 38 | #define METHOD_NAME__HPP "_HPP" |
| 39 | #define METHOD_NAME_OSHP "OSHP" |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | static u8 * acpi_path_name( acpi_handle handle) |
| 42 | { |
| 43 | acpi_status status; |
| 44 | static u8 path_name[ACPI_PATHNAME_MAX]; |
| 45 | struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name }; |
| 46 | |
| 47 | memset(path_name, 0, sizeof (path_name)); |
| 48 | status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf); |
| 49 | |
| 50 | if (ACPI_FAILURE(status)) |
| 51 | return NULL; |
| 52 | else |
| 53 | return path_name; |
| 54 | } |
| 55 | |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 56 | static acpi_status |
| 57 | acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | acpi_status status; |
| 60 | u8 nui[4]; |
| 61 | struct acpi_buffer ret_buf = { 0, NULL}; |
| 62 | union acpi_object *ext_obj, *package; |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 63 | u8 *path_name = acpi_path_name(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | int i, len = 0; |
| 65 | |
| 66 | /* get _hpp */ |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 67 | status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | switch (status) { |
| 69 | case AE_BUFFER_OVERFLOW: |
| 70 | ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL); |
| 71 | if (!ret_buf.pointer) { |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 72 | err ("%s:%s alloc for _HPP fail\n", __FUNCTION__, |
| 73 | path_name); |
| 74 | return AE_NO_MEMORY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 76 | status = acpi_evaluate_object(handle, METHOD_NAME__HPP, |
| 77 | NULL, &ret_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | if (ACPI_SUCCESS(status)) |
| 79 | break; |
| 80 | default: |
| 81 | if (ACPI_FAILURE(status)) { |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 82 | dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__, |
| 83 | path_name, status); |
| 84 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | ext_obj = (union acpi_object *) ret_buf.pointer; |
| 89 | if (ext_obj->type != ACPI_TYPE_PACKAGE) { |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 90 | err ("%s:%s _HPP obj not a package\n", __FUNCTION__, |
| 91 | path_name); |
| 92 | status = AE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | goto free_and_return; |
| 94 | } |
| 95 | |
| 96 | len = ext_obj->package.count; |
| 97 | package = (union acpi_object *) ret_buf.pointer; |
| 98 | for ( i = 0; (i < len) || (i < 4); i++) { |
| 99 | ext_obj = (union acpi_object *) &package->package.elements[i]; |
| 100 | switch (ext_obj->type) { |
| 101 | case ACPI_TYPE_INTEGER: |
| 102 | nui[i] = (u8)ext_obj->integer.value; |
| 103 | break; |
| 104 | default: |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 105 | err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__, |
| 106 | path_name); |
| 107 | status = AE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | goto free_and_return; |
| 109 | } |
| 110 | } |
| 111 | |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 112 | hpp->cache_line_size = nui[0]; |
| 113 | hpp->latency_timer = nui[1]; |
| 114 | hpp->enable_serr = nui[2]; |
| 115 | hpp->enable_perr = nui[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 117 | dbg(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size); |
| 118 | dbg(" _HPP: latency timer =0x%x\n", hpp->latency_timer); |
| 119 | dbg(" _HPP: enable SERR =0x%x\n", hpp->enable_serr); |
| 120 | dbg(" _HPP: enable PERR =0x%x\n", hpp->enable_perr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | free_and_return: |
| 123 | kfree(ret_buf.pointer); |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 124 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 127 | static acpi_status acpi_run_oshp(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
| 129 | acpi_status status; |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 130 | u8 *path_name = acpi_path_name(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | /* run OSHP */ |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 133 | status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | if (ACPI_FAILURE(status)) { |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 135 | dbg("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name, |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 136 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } else { |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 138 | dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 140 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 143 | static int is_root_bridge(acpi_handle handle) |
| 144 | { |
| 145 | acpi_status status; |
| 146 | struct acpi_device_info *info; |
| 147 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 148 | int i; |
| 149 | |
| 150 | status = acpi_get_object_info(handle, &buffer); |
| 151 | if (ACPI_SUCCESS(status)) { |
| 152 | info = buffer.pointer; |
| 153 | if ((info->valid & ACPI_VALID_HID) && |
| 154 | !strcmp(PCI_ROOT_HID_STRING, |
| 155 | info->hardware_id.value)) { |
| 156 | acpi_os_free(buffer.pointer); |
| 157 | return 1; |
| 158 | } |
| 159 | if (info->valid & ACPI_VALID_CID) { |
| 160 | for (i=0; i < info->compatibility_id.count; i++) { |
| 161 | if (!strcmp(PCI_ROOT_HID_STRING, |
| 162 | info->compatibility_id.id[i].value)) { |
| 163 | acpi_os_free(buffer.pointer); |
| 164 | return 1; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | return 0; |
| 170 | } |
| 171 | |
Rajesh Shah | 6560aa5 | 2005-11-07 13:37:36 -0800 | [diff] [blame] | 172 | int pciehp_get_hp_hw_control_from_firmware(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 174 | acpi_status status; |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 175 | acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev)); |
| 176 | struct pci_dev *pdev = dev; |
Jesper Juhl | c2dea65 | 2005-12-11 06:43:09 +0100 | [diff] [blame^] | 177 | struct pci_bus *parent; |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 178 | u8 *path_name; |
Jesper Juhl | c2dea65 | 2005-12-11 06:43:09 +0100 | [diff] [blame^] | 179 | |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 180 | /* |
| 181 | * Per PCI firmware specification, we should run the ACPI _OSC |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 182 | * method to get control of hotplug hardware before using it. |
| 183 | * If an _OSC is missing, we look for an OSHP to do the same thing. |
| 184 | * To handle different BIOS behavior, we look for _OSC and OSHP |
| 185 | * within the scope of the hotplug controller and its parents, upto |
| 186 | * the host bridge under which this controller exists. |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 187 | */ |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 188 | while (!handle) { |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 189 | /* |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 190 | * This hotplug controller was not listed in the ACPI name |
| 191 | * space at all. Try to get acpi handle of parent pci bus. |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 192 | */ |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 193 | if (!pdev || !pdev->bus->parent) |
| 194 | break; |
Jesper Juhl | c2dea65 | 2005-12-11 06:43:09 +0100 | [diff] [blame^] | 195 | parent = pdev->bus->parent; |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 196 | dbg("Could not find %s in acpi namespace, trying parent\n", |
| 197 | pci_name(pdev)); |
Jesper Juhl | c2dea65 | 2005-12-11 06:43:09 +0100 | [diff] [blame^] | 198 | if (!parent->self) |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 199 | /* Parent must be a host bridge */ |
| 200 | handle = acpi_get_pci_rootbridge_handle( |
Jesper Juhl | c2dea65 | 2005-12-11 06:43:09 +0100 | [diff] [blame^] | 201 | pci_domain_nr(parent), |
| 202 | parent->number); |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 203 | else |
| 204 | handle = DEVICE_ACPI_HANDLE( |
Jesper Juhl | c2dea65 | 2005-12-11 06:43:09 +0100 | [diff] [blame^] | 205 | &(parent->self->dev)); |
| 206 | pdev = parent->self; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 209 | while (handle) { |
| 210 | path_name = acpi_path_name(handle); |
| 211 | dbg("Trying to get hotplug control for %s \n", path_name); |
| 212 | status = pci_osc_control_set(handle, |
| 213 | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL); |
| 214 | if (status == AE_NOT_FOUND) |
| 215 | status = acpi_run_oshp(handle); |
| 216 | if (ACPI_SUCCESS(status)) { |
| 217 | dbg("Gained control for hotplug HW for pci %s (%s)\n", |
| 218 | pci_name(dev), path_name); |
| 219 | return 0; |
| 220 | } |
| 221 | if (is_root_bridge(handle)) |
| 222 | break; |
| 223 | chandle = handle; |
| 224 | status = acpi_get_parent(chandle, &handle); |
| 225 | if (ACPI_FAILURE(status)) |
| 226 | break; |
| 227 | } |
| 228 | |
| 229 | err("Cannot get control of hotplug hardware for pci %s\n", |
| 230 | pci_name(dev)); |
| 231 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Rajesh Shah | 6560aa5 | 2005-11-07 13:37:36 -0800 | [diff] [blame] | 234 | void pciehp_get_hp_params_from_firmware(struct pci_dev *dev, |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 235 | struct hotplug_params *hpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 237 | acpi_status status = AE_NOT_FOUND; |
| 238 | struct pci_dev *pdev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | /* |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 241 | * _HPP settings apply to all child buses, until another _HPP is |
| 242 | * encountered. If we don't find an _HPP for the input pci dev, |
| 243 | * look for it in the parent device scope since that would apply to |
| 244 | * this pci dev. If we don't find any _HPP, use hardcoded defaults |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | */ |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 246 | while (pdev && (ACPI_FAILURE(status))) { |
| 247 | acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev)); |
| 248 | if (!handle) |
| 249 | break; |
| 250 | status = acpi_run_hpp(handle, hpp); |
| 251 | if (!(pdev->bus->parent)) |
| 252 | break; |
| 253 | /* Check if a parent object supports _HPP */ |
| 254 | pdev = pdev->bus->parent->self; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | } |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 257 | |