blob: c823cfa42eec4dad8e05068c80421924e5abc093 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Accardi8cf4c192005-08-16 15:16:10 -070023 * Send feedback to <kristen.c.accardi@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
25 */
26
27#include <linux/config.h>
28#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/types.h>
31#include <linux/pci.h>
32#include <linux/init.h>
33#include <linux/acpi.h>
34#include <linux/efi.h>
35#include <linux/pci-acpi.h>
36#include <asm/uaccess.h>
37#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <acpi/acpi.h>
39#include <acpi/acpi_bus.h>
40#include <acpi/actypes.h>
41#include "pciehp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#define METHOD_NAME__SUN "_SUN"
44#define METHOD_NAME__HPP "_HPP"
45#define METHOD_NAME_OSHP "OSHP"
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047static u8 * acpi_path_name( acpi_handle handle)
48{
49 acpi_status status;
50 static u8 path_name[ACPI_PATHNAME_MAX];
51 struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name };
52
53 memset(path_name, 0, sizeof (path_name));
54 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
55
56 if (ACPI_FAILURE(status))
57 return NULL;
58 else
59 return path_name;
60}
61
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080062static acpi_status
63acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 acpi_status status;
66 u8 nui[4];
67 struct acpi_buffer ret_buf = { 0, NULL};
68 union acpi_object *ext_obj, *package;
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080069 u8 *path_name = acpi_path_name(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 int i, len = 0;
71
72 /* get _hpp */
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080073 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 switch (status) {
75 case AE_BUFFER_OVERFLOW:
76 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
77 if (!ret_buf.pointer) {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080078 err ("%s:%s alloc for _HPP fail\n", __FUNCTION__,
79 path_name);
80 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080082 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
83 NULL, &ret_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 if (ACPI_SUCCESS(status))
85 break;
86 default:
87 if (ACPI_FAILURE(status)) {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080088 dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
89 path_name, status);
90 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 }
92 }
93
94 ext_obj = (union acpi_object *) ret_buf.pointer;
95 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080096 err ("%s:%s _HPP obj not a package\n", __FUNCTION__,
97 path_name);
98 status = AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 goto free_and_return;
100 }
101
102 len = ext_obj->package.count;
103 package = (union acpi_object *) ret_buf.pointer;
104 for ( i = 0; (i < len) || (i < 4); i++) {
105 ext_obj = (union acpi_object *) &package->package.elements[i];
106 switch (ext_obj->type) {
107 case ACPI_TYPE_INTEGER:
108 nui[i] = (u8)ext_obj->integer.value;
109 break;
110 default:
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800111 err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__,
112 path_name);
113 status = AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 goto free_and_return;
115 }
116 }
117
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800118 hpp->cache_line_size = nui[0];
119 hpp->latency_timer = nui[1];
120 hpp->enable_serr = nui[2];
121 hpp->enable_perr = nui[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800123 dbg(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
124 dbg(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
125 dbg(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
126 dbg(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128free_and_return:
129 kfree(ret_buf.pointer);
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800130 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800133static acpi_status acpi_run_oshp(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 acpi_status status;
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800136 u8 *path_name = acpi_path_name(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 /* run OSHP */
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800139 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (ACPI_FAILURE(status)) {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800141 err("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name,
142 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 } else {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800144 dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800146 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800149int get_hp_hw_control_from_firmware(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800151 acpi_status status;
152 /*
153 * Per PCI firmware specification, we should run the ACPI _OSC
154 * method to get control of hotplug hardware before using it
155 */
156 /* Fixme: run _OSC for a specific host bridge, not all of them */
157 status = pci_osc_control_set(OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800159 /* Fixme: fail native hotplug if _OSC does not exist for root ports */
160 if (status == AE_NOT_FOUND) {
161 /*
162 * Some older BIOS's don't support _OSC but support
163 * OSHP to do the same thing
164 */
165 acpi_handle handle = DEVICE_ACPI_HANDLE(&(dev->dev));
166 if (handle)
167 status = acpi_run_oshp(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 if (ACPI_FAILURE(status)) {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800170 err("Cannot get control of hotplug hardware\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return -1;
172 }
173
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800174 dbg("Sucess getting control of hotplug hardware\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 return 0;
176}
177
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800178void get_hp_params_from_firmware(struct pci_dev *dev,
179 struct hotplug_params *hpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800181 acpi_status status = AE_NOT_FOUND;
182 struct pci_dev *pdev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 /*
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800185 * _HPP settings apply to all child buses, until another _HPP is
186 * encountered. If we don't find an _HPP for the input pci dev,
187 * look for it in the parent device scope since that would apply to
188 * this pci dev. If we don't find any _HPP, use hardcoded defaults
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 */
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800190 while (pdev && (ACPI_FAILURE(status))) {
191 acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
192 if (!handle)
193 break;
194 status = acpi_run_hpp(handle, hpp);
195 if (!(pdev->bus->parent))
196 break;
197 /* Check if a parent object supports _HPP */
198 pdev = pdev->bus->parent->self;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 }
200}
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800201