blob: 5acdae3d52b18bb98789908ad191209bdd319b1a [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/types.h>
30#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/pci-acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <acpi/acpi_bus.h>
34#include <acpi/actypes.h>
35#include "pciehp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#define METHOD_NAME__SUN "_SUN"
38#define METHOD_NAME__HPP "_HPP"
39#define METHOD_NAME_OSHP "OSHP"
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static 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.coma8a2be92005-10-31 16:20:07 -080056static acpi_status
57acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
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.coma8a2be92005-10-31 16:20:07 -080063 u8 *path_name = acpi_path_name(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 int i, len = 0;
65
66 /* get _hpp */
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080067 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 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.coma8a2be92005-10-31 16:20:07 -080072 err ("%s:%s alloc for _HPP fail\n", __FUNCTION__,
73 path_name);
74 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080076 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
77 NULL, &ret_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (ACPI_SUCCESS(status))
79 break;
80 default:
81 if (ACPI_FAILURE(status)) {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080082 dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
83 path_name, status);
84 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
86 }
87
88 ext_obj = (union acpi_object *) ret_buf.pointer;
89 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -080090 err ("%s:%s _HPP obj not a package\n", __FUNCTION__,
91 path_name);
92 status = AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 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.coma8a2be92005-10-31 16:20:07 -0800105 err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__,
106 path_name);
107 status = AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 goto free_and_return;
109 }
110 }
111
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800112 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 Torvalds1da177e2005-04-16 15:20:36 -0700116
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800117 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 Torvalds1da177e2005-04-16 15:20:36 -0700121
122free_and_return:
123 kfree(ret_buf.pointer);
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800124 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
126
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800127static acpi_status acpi_run_oshp(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 acpi_status status;
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800130 u8 *path_name = acpi_path_name(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /* run OSHP */
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800133 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 if (ACPI_FAILURE(status)) {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800135 err("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name,
136 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 } else {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800138 dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 }
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800140 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800143int get_hp_hw_control_from_firmware(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800145 acpi_status status;
rajesh.shah@intel.com427bf532005-10-31 16:20:11 -0800146 acpi_handle handle = DEVICE_ACPI_HANDLE(&(dev->dev));
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800147 /*
148 * Per PCI firmware specification, we should run the ACPI _OSC
149 * method to get control of hotplug hardware before using it
150 */
rajesh.shah@intel.com427bf532005-10-31 16:20:11 -0800151 status = pci_osc_control_set(handle,
152 OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800154 /* Fixme: fail native hotplug if _OSC does not exist for root ports */
155 if (status == AE_NOT_FOUND) {
156 /*
157 * Some older BIOS's don't support _OSC but support
158 * OSHP to do the same thing
159 */
rajesh.shah@intel.com427bf532005-10-31 16:20:11 -0800160 status = acpi_run_oshp(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 if (ACPI_FAILURE(status)) {
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800163 err("Cannot get control of hotplug hardware\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 return -1;
165 }
166
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800167 dbg("Sucess getting control of hotplug hardware\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return 0;
169}
170
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800171void get_hp_params_from_firmware(struct pci_dev *dev,
172 struct hotplug_params *hpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800174 acpi_status status = AE_NOT_FOUND;
175 struct pci_dev *pdev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 /*
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800178 * _HPP settings apply to all child buses, until another _HPP is
179 * encountered. If we don't find an _HPP for the input pci dev,
180 * look for it in the parent device scope since that would apply to
181 * this pci dev. If we don't find any _HPP, use hardcoded defaults
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 */
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800183 while (pdev && (ACPI_FAILURE(status))) {
184 acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
185 if (!handle)
186 break;
187 status = acpi_run_hpp(handle, hpp);
188 if (!(pdev->bus->parent))
189 break;
190 /* Check if a parent object supports _HPP */
191 pdev = pdev->bus->parent->self;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
193}
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -0800194