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
;
37 union acpi_object out_obj
;
40 /* Setting up output buffer */
41 output
.length
= sizeof(out_obj
) + 3*sizeof(u32
);
42 output
.pointer
= &out_obj
;
44 /* Setting up input parameters */
46 input
.pointer
= in_params
;
47 in_params
[0].type
= ACPI_TYPE_BUFFER
;
48 in_params
[0].buffer
.length
= 16;
49 in_params
[0].buffer
.pointer
= OSC_UUID
;
50 in_params
[1].type
= ACPI_TYPE_INTEGER
;
51 in_params
[1].integer
.value
= 1;
52 in_params
[2].type
= ACPI_TYPE_INTEGER
;
53 in_params
[2].integer
.value
= 3;
54 in_params
[3].type
= ACPI_TYPE_BUFFER
;
55 in_params
[3].buffer
.length
= 12;
56 in_params
[3].buffer
.pointer
= (u8
*)context
;
58 status
= acpi_evaluate_object(handle
, "_OSC", &input
, &output
);
59 if (ACPI_FAILURE (status
)) {
61 "Evaluate _OSC Set fails. Status = 0x%04x\n", status
);
64 if (out_obj
.type
!= ACPI_TYPE_BUFFER
) {
66 "Evaluate _OSC returns wrong type\n");
69 osc_dw0
= *((u32
*) out_obj
.buffer
.pointer
);
71 if (osc_dw0
& OSC_REQUEST_ERROR
)
72 printk(KERN_DEBUG
"_OSC request fails\n");
73 if (osc_dw0
& OSC_INVALID_UUID_ERROR
)
74 printk(KERN_DEBUG
"_OSC invalid UUID\n");
75 if (osc_dw0
& OSC_INVALID_REVISION_ERROR
)
76 printk(KERN_DEBUG
"_OSC invalid revision\n");
77 if (osc_dw0
& OSC_CAPABILITIES_MASK_ERROR
) {
78 /* Update Global Control Set */
79 global_ctrlsets
= *((u32
*)(out_obj
.buffer
.pointer
+8));
85 /* Update Global Control Set */
86 global_ctrlsets
= *((u32
*)(out_obj
.buffer
.pointer
+ 8));
99 struct acpi_object_list input
;
100 union acpi_object in_params
[4];
101 struct acpi_buffer output
;
102 union acpi_object out_obj
;
105 /* Setting up output buffer */
106 output
.length
= sizeof(out_obj
) + 3*sizeof(u32
);
107 output
.pointer
= &out_obj
;
109 /* Setting up input parameters */
111 input
.pointer
= in_params
;
112 in_params
[0].type
= ACPI_TYPE_BUFFER
;
113 in_params
[0].buffer
.length
= 16;
114 in_params
[0].buffer
.pointer
= OSC_UUID
;
115 in_params
[1].type
= ACPI_TYPE_INTEGER
;
116 in_params
[1].integer
.value
= 1;
117 in_params
[2].type
= ACPI_TYPE_INTEGER
;
118 in_params
[2].integer
.value
= 3;
119 in_params
[3].type
= ACPI_TYPE_BUFFER
;
120 in_params
[3].buffer
.length
= 12;
121 in_params
[3].buffer
.pointer
= (u8
*)context
;
123 status
= acpi_evaluate_object(handle
, "_OSC", &input
, &output
);
124 if (ACPI_FAILURE (status
)) {
126 "Evaluate _OSC Set fails. Status = 0x%04x\n", status
);
129 if (out_obj
.type
!= ACPI_TYPE_BUFFER
) {
131 "Evaluate _OSC returns wrong type\n");
134 osc_dw0
= *((u32
*) out_obj
.buffer
.pointer
);
136 if (osc_dw0
& OSC_REQUEST_ERROR
)
137 printk(KERN_DEBUG
"_OSC request fails\n");
138 if (osc_dw0
& OSC_INVALID_UUID_ERROR
)
139 printk(KERN_DEBUG
"_OSC invalid UUID\n");
140 if (osc_dw0
& OSC_INVALID_REVISION_ERROR
)
141 printk(KERN_DEBUG
"_OSC invalid revision\n");
142 if (osc_dw0
& OSC_CAPABILITIES_MASK_ERROR
) {
143 printk(KERN_DEBUG
"_OSC FW not grant req. control\n");
152 * pci_osc_support_set - register OS support to Firmware
153 * @flags: OS support bits
155 * Update OS support fields and doing a _OSC Query to obtain an update
156 * from Firmware on supported control bits.
158 acpi_status
pci_osc_support_set(u32 flags
)
162 if (!(flags
& OSC_SUPPORT_MASKS
)) {
165 ctrlset_buf
[OSC_SUPPORT_TYPE
] |= (flags
& OSC_SUPPORT_MASKS
);
167 /* do _OSC query for all possible controls */
168 temp
= ctrlset_buf
[OSC_CONTROL_TYPE
];
169 ctrlset_buf
[OSC_QUERY_TYPE
] = OSC_QUERY_ENABLE
;
170 ctrlset_buf
[OSC_CONTROL_TYPE
] = OSC_CONTROL_MASKS
;
171 acpi_get_devices ( PCI_ROOT_HID_STRING
,
175 ctrlset_buf
[OSC_QUERY_TYPE
] = !OSC_QUERY_ENABLE
;
176 ctrlset_buf
[OSC_CONTROL_TYPE
] = temp
;
179 EXPORT_SYMBOL(pci_osc_support_set
);
182 * pci_osc_control_set - commit requested control to Firmware
183 * @flags: driver's requested control bits
185 * Attempt to take control from Firmware on requested control bits.
187 acpi_status
pci_osc_control_set(u32 flags
)
192 ctrlset
= (flags
& OSC_CONTROL_MASKS
);
196 if (ctrlset_buf
[OSC_SUPPORT_TYPE
] &&
197 ((global_ctrlsets
& ctrlset
) != ctrlset
)) {
200 ctrlset_buf
[OSC_CONTROL_TYPE
] |= ctrlset
;
201 status
= acpi_get_devices ( PCI_ROOT_HID_STRING
,
205 if (ACPI_FAILURE (status
)) {
206 ctrlset_buf
[OSC_CONTROL_TYPE
] &= ~ctrlset
;
211 EXPORT_SYMBOL(pci_osc_control_set
);
214 * _SxD returns the D-state with the highest power
215 * (lowest D-state number) supported in the S-state "x".
217 * If the devices does not have a _PRW
218 * (Power Resources for Wake) supporting system wakeup from "x"
219 * then the OS is free to choose a lower power (higher number
220 * D-state) than the return value from _SxD.
222 * But if _PRW is enabled at S-state "x", the OS
223 * must not choose a power lower than _SxD --
224 * unless the device has an _SxW method specifying
225 * the lowest power (highest D-state number) the device
226 * may enter while still able to wake the system.
228 * ie. depending on global OS policy:
230 * if (_PRW at S-state x)
231 * choose from highest power _SxD to lowest power _SxW
232 * else // no _PRW at S-state x
233 * choose highest power _SxD or any lower power
235 * currently we simply return _SxD, if present.
238 static int acpi_pci_choose_state(struct pci_dev
*pdev
, pm_message_t state
)
245 static int acpi_pci_set_power_state(struct pci_dev
*dev
, pci_power_t state
)
247 acpi_handle handle
= DEVICE_ACPI_HANDLE(&dev
->dev
);
248 static int state_conv
[] = {
255 int acpi_state
= state_conv
[(int __force
) state
];
259 return acpi_bus_set_power(handle
, acpi_state
);
264 static int pci_acpi_find_device(struct device
*dev
, acpi_handle
*handle
)
266 struct pci_dev
* pci_dev
;
269 pci_dev
= to_pci_dev(dev
);
270 /* Please ref to ACPI spec for the syntax of _ADR */
271 addr
= (PCI_SLOT(pci_dev
->devfn
) << 16) | PCI_FUNC(pci_dev
->devfn
);
272 *handle
= acpi_get_child(DEVICE_ACPI_HANDLE(dev
->parent
), addr
);
278 static int pci_acpi_find_root_bridge(struct device
*dev
, acpi_handle
*handle
)
281 unsigned int seg
, bus
;
284 * The string should be the same as root bridge's name
285 * Please look at 'pci_scan_bus_parented'
287 num
= sscanf(dev
->bus_id
, "pci%04x:%02x", &seg
, &bus
);
290 *handle
= acpi_get_pci_rootbridge_handle(seg
, bus
);
296 static struct acpi_bus_type pci_acpi_bus
= {
297 .bus
= &pci_bus_type
,
298 .find_device
= pci_acpi_find_device
,
299 .find_bridge
= pci_acpi_find_root_bridge
,
302 static int __init
pci_acpi_init(void)
306 ret
= register_acpi_bus_type(&pci_acpi_bus
);
309 platform_pci_choose_state
= acpi_pci_choose_state
;
310 platform_pci_set_power_state
= acpi_pci_set_power_state
;
313 arch_initcall(pci_acpi_init
);