blob: 3be518c7d47a3dcdab59c55ca385f005ecf2e977 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 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 <asm/uaccess.h>
36#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <acpi/acpi.h>
38#include <acpi/acpi_bus.h>
39#include <acpi/actypes.h>
40#include "shpchp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#define METHOD_NAME__SUN "_SUN"
43#define METHOD_NAME__HPP "_HPP"
44#define METHOD_NAME_OSHP "OSHP"
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046static u8 * acpi_path_name( acpi_handle handle)
47{
48 acpi_status status;
49 static u8 path_name[ACPI_PATHNAME_MAX];
50 struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name };
51
52 memset(path_name, 0, sizeof (path_name));
53 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
54
55 if (ACPI_FAILURE(status))
56 return NULL;
57 else
58 return path_name;
59}
60
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -070061static acpi_status
62acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 acpi_status status;
65 u8 nui[4];
66 struct acpi_buffer ret_buf = { 0, NULL};
67 union acpi_object *ext_obj, *package;
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -070068 u8 *path_name = acpi_path_name(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 int i, len = 0;
70
71 /* get _hpp */
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -070072 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 switch (status) {
74 case AE_BUFFER_OVERFLOW:
75 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
76 if (!ret_buf.pointer) {
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -070077 err ("%s:%s alloc for _HPP fail\n", __FUNCTION__,
78 path_name);
79 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 }
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -070081 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
82 NULL, &ret_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 if (ACPI_SUCCESS(status))
84 break;
85 default:
86 if (ACPI_FAILURE(status)) {
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -070087 dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
88 path_name, status);
89 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 }
91 }
92
93 ext_obj = (union acpi_object *) ret_buf.pointer;
94 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -070095 err ("%s:%s _HPP obj not a package\n", __FUNCTION__,
96 path_name);
97 status = AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 goto free_and_return;
99 }
100
101 len = ext_obj->package.count;
102 package = (union acpi_object *) ret_buf.pointer;
103 for ( i = 0; (i < len) || (i < 4); i++) {
104 ext_obj = (union acpi_object *) &package->package.elements[i];
105 switch (ext_obj->type) {
106 case ACPI_TYPE_INTEGER:
107 nui[i] = (u8)ext_obj->integer.value;
108 break;
109 default:
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700110 err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__,
111 path_name);
112 status = AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 goto free_and_return;
114 }
115 }
116
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700117 hpp->cache_line_size = nui[0];
118 hpp->latency_timer = nui[1];
119 hpp->enable_serr = nui[2];
120 hpp->enable_perr = nui[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700122 dbg(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
123 dbg(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
124 dbg(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
125 dbg(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127free_and_return:
128 kfree(ret_buf.pointer);
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700129 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700132static void acpi_run_oshp(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
134 acpi_status status;
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700135 u8 *path_name = acpi_path_name(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 /* run OSHP */
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700138 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 if (ACPI_FAILURE(status)) {
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700140 err("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name,
141 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 } else {
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700143 dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum)
148{
149 int offset = devnum - ctrl->slot_device_offset;
150
151 dbg("%s: ctrl->slot_num_inc %d, offset %d\n", __FUNCTION__, ctrl->slot_num_inc, offset);
152 *sun = (u8) (ctrl->first_slot + ctrl->slot_num_inc *offset);
153 return 0;
154}
155
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700156void get_hp_hw_control_from_firmware(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700158 /*
159 * OSHP is an optional ACPI firmware control method. If present,
160 * we need to run it to inform BIOS that we will control SHPC
161 * hardware from now on.
162 */
163 acpi_handle handle = DEVICE_ACPI_HANDLE(&(dev->dev));
164 if (!handle)
165 return;
166 acpi_run_oshp(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700169void get_hp_params_from_firmware(struct pci_dev *dev,
170 struct hotplug_params *hpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700172 acpi_status status = AE_NOT_FOUND;
173 struct pci_dev *pdev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700175 /*
176 * _HPP settings apply to all child buses, until another _HPP is
177 * encountered. If we don't find an _HPP for the input pci dev,
178 * look for it in the parent device scope since that would apply to
179 * this pci dev. If we don't find any _HPP, use hardcoded defaults
180 */
181 while (pdev && (ACPI_FAILURE(status))) {
182 acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
183 if (!handle)
184 break;
185 status = acpi_run_hpp(handle, hpp);
186 if (!(pdev->bus->parent))
187 break;
188 /* Check if a parent object supports _HPP */
189 pdev = pdev->bus->parent->self;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 }
191}
192