Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * SHPCHPRM 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 <acpi/acpi.h> |
| 32 | #include <acpi/acpi_bus.h> |
| 33 | #include <acpi/actypes.h> |
| 34 | #include "shpchp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #define METHOD_NAME__SUN "_SUN" |
| 37 | #define METHOD_NAME__HPP "_HPP" |
| 38 | #define METHOD_NAME_OSHP "OSHP" |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | static u8 * acpi_path_name( acpi_handle handle) |
| 41 | { |
| 42 | acpi_status status; |
| 43 | static u8 path_name[ACPI_PATHNAME_MAX]; |
| 44 | struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name }; |
| 45 | |
| 46 | memset(path_name, 0, sizeof (path_name)); |
| 47 | status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf); |
| 48 | |
| 49 | if (ACPI_FAILURE(status)) |
| 50 | return NULL; |
| 51 | else |
| 52 | return path_name; |
| 53 | } |
| 54 | |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 55 | static acpi_status |
| 56 | acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
| 58 | acpi_status status; |
| 59 | u8 nui[4]; |
| 60 | struct acpi_buffer ret_buf = { 0, NULL}; |
| 61 | union acpi_object *ext_obj, *package; |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 62 | u8 *path_name = acpi_path_name(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | int i, len = 0; |
| 64 | |
| 65 | /* get _hpp */ |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 66 | status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | switch (status) { |
| 68 | case AE_BUFFER_OVERFLOW: |
| 69 | ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL); |
| 70 | if (!ret_buf.pointer) { |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 71 | err ("%s:%s alloc for _HPP fail\n", __FUNCTION__, |
| 72 | path_name); |
| 73 | return AE_NO_MEMORY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 75 | status = acpi_evaluate_object(handle, METHOD_NAME__HPP, |
| 76 | NULL, &ret_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | if (ACPI_SUCCESS(status)) |
| 78 | break; |
| 79 | default: |
| 80 | if (ACPI_FAILURE(status)) { |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 81 | dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__, |
| 82 | path_name, status); |
| 83 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
| 87 | ext_obj = (union acpi_object *) ret_buf.pointer; |
| 88 | if (ext_obj->type != ACPI_TYPE_PACKAGE) { |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 89 | err ("%s:%s _HPP obj not a package\n", __FUNCTION__, |
| 90 | path_name); |
| 91 | status = AE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | goto free_and_return; |
| 93 | } |
| 94 | |
| 95 | len = ext_obj->package.count; |
| 96 | package = (union acpi_object *) ret_buf.pointer; |
| 97 | for ( i = 0; (i < len) || (i < 4); i++) { |
| 98 | ext_obj = (union acpi_object *) &package->package.elements[i]; |
| 99 | switch (ext_obj->type) { |
| 100 | case ACPI_TYPE_INTEGER: |
| 101 | nui[i] = (u8)ext_obj->integer.value; |
| 102 | break; |
| 103 | default: |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 104 | err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__, |
| 105 | path_name); |
| 106 | status = AE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | goto free_and_return; |
| 108 | } |
| 109 | } |
| 110 | |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 111 | hpp->cache_line_size = nui[0]; |
| 112 | hpp->latency_timer = nui[1]; |
| 113 | hpp->enable_serr = nui[2]; |
| 114 | hpp->enable_perr = nui[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 116 | dbg(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size); |
| 117 | dbg(" _HPP: latency timer =0x%x\n", hpp->latency_timer); |
| 118 | dbg(" _HPP: enable SERR =0x%x\n", hpp->enable_serr); |
| 119 | dbg(" _HPP: enable PERR =0x%x\n", hpp->enable_perr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | free_and_return: |
| 122 | kfree(ret_buf.pointer); |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 123 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 126 | static void acpi_run_oshp(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
| 128 | acpi_status status; |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 129 | u8 *path_name = acpi_path_name(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /* run OSHP */ |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 132 | status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | if (ACPI_FAILURE(status)) { |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 134 | err("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name, |
| 135 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } else { |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 137 | dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum) |
| 142 | { |
| 143 | int offset = devnum - ctrl->slot_device_offset; |
| 144 | |
| 145 | dbg("%s: ctrl->slot_num_inc %d, offset %d\n", __FUNCTION__, ctrl->slot_num_inc, offset); |
| 146 | *sun = (u8) (ctrl->first_slot + ctrl->slot_num_inc *offset); |
| 147 | return 0; |
| 148 | } |
| 149 | |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 150 | void get_hp_hw_control_from_firmware(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 152 | /* |
| 153 | * OSHP is an optional ACPI firmware control method. If present, |
| 154 | * we need to run it to inform BIOS that we will control SHPC |
| 155 | * hardware from now on. |
| 156 | */ |
| 157 | acpi_handle handle = DEVICE_ACPI_HANDLE(&(dev->dev)); |
| 158 | if (!handle) |
| 159 | return; |
| 160 | acpi_run_oshp(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 163 | void get_hp_params_from_firmware(struct pci_dev *dev, |
| 164 | struct hotplug_params *hpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 166 | acpi_status status = AE_NOT_FOUND; |
| 167 | struct pci_dev *pdev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 169 | /* |
| 170 | * _HPP settings apply to all child buses, until another _HPP is |
| 171 | * encountered. If we don't find an _HPP for the input pci dev, |
| 172 | * look for it in the parent device scope since that would apply to |
| 173 | * this pci dev. If we don't find any _HPP, use hardcoded defaults |
| 174 | */ |
| 175 | while (pdev && (ACPI_FAILURE(status))) { |
| 176 | acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev)); |
| 177 | if (!handle) |
| 178 | break; |
| 179 | status = acpi_run_hpp(handle, hpp); |
| 180 | if (!(pdev->bus->parent)) |
| 181 | break; |
| 182 | /* Check if a parent object supports _HPP */ |
| 183 | pdev = pdev->bus->parent->self; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |