3 * Purpose: Provide PCI support in ACPI
5 * Copyright (C) 2005 David Shaohua Li <shaohua.li@intel.com>
6 * Copyright (C) 2004 Tom Long Nguyen <tom.l.nguyen@intel.com>
7 * Copyright (C) 2004 Intel Corp.
10 #include <linux/delay.h>
11 #include <linux/init.h>
12 #include <linux/pci.h>
13 #include <linux/module.h>
14 #include <acpi/acpi.h>
15 #include <acpi/acnamesp.h>
16 #include <acpi/acresrc.h>
17 #include <acpi/acpi_bus.h>
19 #include <linux/pci-acpi.h>
22 static u32 ctrlset_buf[3] = {0, 0, 0};
23 static u32 global_ctrlsets = 0;
24 static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40, 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66};
34 struct acpi_object_list input;
35 union acpi_object in_params[4];
36 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
37 union acpi_object *out_obj;
39 acpi_status *ret_status = (acpi_status *)retval;
42 /* Setting up input parameters */
44 input.pointer = in_params;
45 in_params[0].type = ACPI_TYPE_BUFFER;
46 in_params[0].buffer.length = 16;
47 in_params[0].buffer.pointer = OSC_UUID;
48 in_params[1].type = ACPI_TYPE_INTEGER;
49 in_params[1].integer.value = 1;
50 in_params[2].type = ACPI_TYPE_INTEGER;
51 in_params[2].integer.value = 3;
52 in_params[3].type = ACPI_TYPE_BUFFER;
53 in_params[3].buffer.length = 12;
54 in_params[3].buffer.pointer = (u8 *)context;
56 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
57 if (ACPI_FAILURE (status)) {
59 "Evaluate _OSC Set fails. Status = 0x%04x\n", status);
63 out_obj = output.pointer;
65 if (out_obj->type != ACPI_TYPE_BUFFER) {
67 "Evaluate _OSC returns wrong type\n");
71 osc_dw0 = *((u32 *) out_obj->buffer.pointer);
73 if (osc_dw0 & OSC_REQUEST_ERROR)
74 printk(KERN_DEBUG "_OSC request fails\n");
75 if (osc_dw0 & OSC_INVALID_UUID_ERROR)
76 printk(KERN_DEBUG "_OSC invalid UUID\n");
77 if (osc_dw0 & OSC_INVALID_REVISION_ERROR)
78 printk(KERN_DEBUG "_OSC invalid revision\n");
79 if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) {
80 /* Update Global Control Set */
81 global_ctrlsets = *((u32 *)(out_obj->buffer.pointer+8));
89 /* Update Global Control Set */
90 global_ctrlsets = *((u32 *)(out_obj->buffer.pointer + 8));
94 kfree(output.pointer);
106 struct acpi_object_list input;
107 union acpi_object in_params[4];
108 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
109 union acpi_object *out_obj;
112 /* Setting up input parameters */
114 input.pointer = in_params;
115 in_params[0].type = ACPI_TYPE_BUFFER;
116 in_params[0].buffer.length = 16;
117 in_params[0].buffer.pointer = OSC_UUID;
118 in_params[1].type = ACPI_TYPE_INTEGER;
119 in_params[1].integer.value = 1;
120 in_params[2].type = ACPI_TYPE_INTEGER;
121 in_params[2].integer.value = 3;
122 in_params[3].type = ACPI_TYPE_BUFFER;
123 in_params[3].buffer.length = 12;
124 in_params[3].buffer.pointer = (u8 *)context;
126 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
127 if (ACPI_FAILURE (status)) {
129 "Evaluate _OSC Set fails. Status = 0x%04x\n", status);
132 out_obj = output.pointer;
133 if (out_obj->type != ACPI_TYPE_BUFFER) {
135 "Evaluate _OSC returns wrong type\n");
139 osc_dw0 = *((u32 *) out_obj->buffer.pointer);
141 if (osc_dw0 & OSC_REQUEST_ERROR)
142 printk(KERN_DEBUG "_OSC request fails\n");
143 if (osc_dw0 & OSC_INVALID_UUID_ERROR)
144 printk(KERN_DEBUG "_OSC invalid UUID\n");
145 if (osc_dw0 & OSC_INVALID_REVISION_ERROR)
146 printk(KERN_DEBUG "_OSC invalid revision\n");
147 if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) {
148 printk(KERN_DEBUG "_OSC FW not grant req. control\n");
158 kfree(output.pointer);
163 * pci_osc_support_set - register OS support to Firmware
164 * @flags: OS support bits
166 * Update OS support fields and doing a _OSC Query to obtain an update
167 * from Firmware on supported control bits.
169 acpi_status pci_osc_support_set(u32 flags)
174 if (!(flags & OSC_SUPPORT_MASKS)) {
177 ctrlset_buf[OSC_SUPPORT_TYPE] |= (flags & OSC_SUPPORT_MASKS);
179 /* do _OSC query for all possible controls */
180 temp = ctrlset_buf[OSC_CONTROL_TYPE];
181 ctrlset_buf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
182 ctrlset_buf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS;
183 acpi_get_devices ( PCI_ROOT_HID_STRING,
187 ctrlset_buf[OSC_QUERY_TYPE] = !OSC_QUERY_ENABLE;
188 ctrlset_buf[OSC_CONTROL_TYPE] = temp;
189 if (ACPI_FAILURE(retval)) {
190 /* no osc support at all */
191 ctrlset_buf[OSC_SUPPORT_TYPE] = 0;
195 EXPORT_SYMBOL(pci_osc_support_set);
198 * pci_osc_control_set - commit requested control to Firmware
199 * @handle: acpi_handle for the target ACPI object
200 * @flags: driver's requested control bits
202 * Attempt to take control from Firmware on requested control bits.
204 acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
209 ctrlset = (flags & OSC_CONTROL_MASKS);
213 if (ctrlset_buf[OSC_SUPPORT_TYPE] &&
214 ((global_ctrlsets & ctrlset) != ctrlset)) {
217 ctrlset_buf[OSC_CONTROL_TYPE] |= ctrlset;
218 status = acpi_run_osc(handle, ctrlset_buf);
219 if (ACPI_FAILURE (status)) {
220 ctrlset_buf[OSC_CONTROL_TYPE] &= ~ctrlset;
225 EXPORT_SYMBOL(pci_osc_control_set);
228 * _SxD returns the D-state with the highest power
229 * (lowest D-state number) supported in the S-state "x".
231 * If the devices does not have a _PRW
232 * (Power Resources for Wake) supporting system wakeup from "x"
233 * then the OS is free to choose a lower power (higher number
234 * D-state) than the return value from _SxD.
236 * But if _PRW is enabled at S-state "x", the OS
237 * must not choose a power lower than _SxD --
238 * unless the device has an _SxW method specifying
239 * the lowest power (highest D-state number) the device
240 * may enter while still able to wake the system.
242 * ie. depending on global OS policy:
244 * if (_PRW at S-state x)
245 * choose from highest power _SxD to lowest power _SxW
246 * else // no _PRW at S-state x
247 * choose highest power _SxD or any lower power
249 * currently we simply return _SxD, if present.
252 static int acpi_pci_choose_state(struct pci_dev *pdev, pm_message_t state)
259 static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
261 acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
262 static int state_conv[] = {
269 int acpi_state = state_conv[(int __force) state];
273 return acpi_bus_set_power(handle, acpi_state);
278 static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
280 struct pci_dev * pci_dev;
283 pci_dev = to_pci_dev(dev);
284 /* Please ref to ACPI spec for the syntax of _ADR */
285 addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
286 *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
292 static int acpi_pci_find_root_bridge(struct device *dev, acpi_handle *handle)
295 unsigned int seg, bus;
298 * The string should be the same as root bridge's name
299 * Please look at 'pci_scan_bus_parented'
301 num = sscanf(dev->bus_id, "pci%04x:%02x", &seg, &bus);
304 *handle = acpi_get_pci_rootbridge_handle(seg, bus);
310 static struct acpi_bus_type acpi_pci_bus = {
311 .bus = &pci_bus_type,
312 .find_device = acpi_pci_find_device,
313 .find_bridge = acpi_pci_find_root_bridge,
316 static int __init acpi_pci_init(void)
320 if (acpi_gbl_FADT.boot_flags & BAF_MSI_NOT_SUPPORTED) {
321 printk(KERN_INFO"ACPI FADT declares the system doesn't support MSI, so disable it\n");
324 ret = register_acpi_bus_type(&acpi_pci_bus);
327 platform_pci_choose_state = acpi_pci_choose_state;
328 platform_pci_set_power_state = acpi_pci_set_power_state;
331 arch_initcall(acpi_pci_init);