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>
21 static u32 ctrlset_buf
[3] = {0, 0, 0};
22 static u32 global_ctrlsets
= 0;
23 static u8 OSC_UUID
[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40, 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66};
33 struct acpi_object_list input
;
34 union acpi_object in_params
[4];
35 struct acpi_buffer output
;
36 union acpi_object out_obj
;
39 /* Setting up output buffer */
40 output
.length
= sizeof(out_obj
) + 3*sizeof(u32
);
41 output
.pointer
= &out_obj
;
43 /* Setting up input parameters */
45 input
.pointer
= in_params
;
46 in_params
[0].type
= ACPI_TYPE_BUFFER
;
47 in_params
[0].buffer
.length
= 16;
48 in_params
[0].buffer
.pointer
= OSC_UUID
;
49 in_params
[1].type
= ACPI_TYPE_INTEGER
;
50 in_params
[1].integer
.value
= 1;
51 in_params
[2].type
= ACPI_TYPE_INTEGER
;
52 in_params
[2].integer
.value
= 3;
53 in_params
[3].type
= ACPI_TYPE_BUFFER
;
54 in_params
[3].buffer
.length
= 12;
55 in_params
[3].buffer
.pointer
= (u8
*)context
;
57 status
= acpi_evaluate_object(handle
, "_OSC", &input
, &output
);
58 if (ACPI_FAILURE (status
)) {
60 "Evaluate _OSC Set fails. Status = 0x%04x\n", status
);
63 if (out_obj
.type
!= ACPI_TYPE_BUFFER
) {
65 "Evaluate _OSC returns wrong type\n");
68 osc_dw0
= *((u32
*) out_obj
.buffer
.pointer
);
70 if (osc_dw0
& OSC_REQUEST_ERROR
)
71 printk(KERN_DEBUG
"_OSC request fails\n");
72 if (osc_dw0
& OSC_INVALID_UUID_ERROR
)
73 printk(KERN_DEBUG
"_OSC invalid UUID\n");
74 if (osc_dw0
& OSC_INVALID_REVISION_ERROR
)
75 printk(KERN_DEBUG
"_OSC invalid revision\n");
76 if (osc_dw0
& OSC_CAPABILITIES_MASK_ERROR
) {
77 /* Update Global Control Set */
78 global_ctrlsets
= *((u32
*)(out_obj
.buffer
.pointer
+8));
84 /* Update Global Control Set */
85 global_ctrlsets
= *((u32
*)(out_obj
.buffer
.pointer
+ 8));
98 struct acpi_object_list input
;
99 union acpi_object in_params
[4];
100 struct acpi_buffer output
;
101 union acpi_object out_obj
;
104 /* Setting up output buffer */
105 output
.length
= sizeof(out_obj
) + 3*sizeof(u32
);
106 output
.pointer
= &out_obj
;
108 /* Setting up input parameters */
110 input
.pointer
= in_params
;
111 in_params
[0].type
= ACPI_TYPE_BUFFER
;
112 in_params
[0].buffer
.length
= 16;
113 in_params
[0].buffer
.pointer
= OSC_UUID
;
114 in_params
[1].type
= ACPI_TYPE_INTEGER
;
115 in_params
[1].integer
.value
= 1;
116 in_params
[2].type
= ACPI_TYPE_INTEGER
;
117 in_params
[2].integer
.value
= 3;
118 in_params
[3].type
= ACPI_TYPE_BUFFER
;
119 in_params
[3].buffer
.length
= 12;
120 in_params
[3].buffer
.pointer
= (u8
*)context
;
122 status
= acpi_evaluate_object(handle
, "_OSC", &input
, &output
);
123 if (ACPI_FAILURE (status
)) {
125 "Evaluate _OSC Set fails. Status = 0x%04x\n", status
);
128 if (out_obj
.type
!= ACPI_TYPE_BUFFER
) {
130 "Evaluate _OSC returns wrong type\n");
133 osc_dw0
= *((u32
*) out_obj
.buffer
.pointer
);
135 if (osc_dw0
& OSC_REQUEST_ERROR
)
136 printk(KERN_DEBUG
"_OSC request fails\n");
137 if (osc_dw0
& OSC_INVALID_UUID_ERROR
)
138 printk(KERN_DEBUG
"_OSC invalid UUID\n");
139 if (osc_dw0
& OSC_INVALID_REVISION_ERROR
)
140 printk(KERN_DEBUG
"_OSC invalid revision\n");
141 if (osc_dw0
& OSC_CAPABILITIES_MASK_ERROR
) {
142 printk(KERN_DEBUG
"_OSC FW not grant req. control\n");
151 * pci_osc_support_set - register OS support to Firmware
152 * @flags: OS support bits
154 * Update OS support fields and doing a _OSC Query to obtain an update
155 * from Firmware on supported control bits.
157 acpi_status
pci_osc_support_set(u32 flags
)
161 if (!(flags
& OSC_SUPPORT_MASKS
)) {
164 ctrlset_buf
[OSC_SUPPORT_TYPE
] |= (flags
& OSC_SUPPORT_MASKS
);
166 /* do _OSC query for all possible controls */
167 temp
= ctrlset_buf
[OSC_CONTROL_TYPE
];
168 ctrlset_buf
[OSC_QUERY_TYPE
] = OSC_QUERY_ENABLE
;
169 ctrlset_buf
[OSC_CONTROL_TYPE
] = OSC_CONTROL_MASKS
;
170 acpi_get_devices ( PCI_ROOT_HID_STRING
,
174 ctrlset_buf
[OSC_QUERY_TYPE
] = !OSC_QUERY_ENABLE
;
175 ctrlset_buf
[OSC_CONTROL_TYPE
] = temp
;
178 EXPORT_SYMBOL(pci_osc_support_set
);
181 * pci_osc_control_set - commit requested control to Firmware
182 * @flags: driver's requested control bits
184 * Attempt to take control from Firmware on requested control bits.
186 acpi_status
pci_osc_control_set(u32 flags
)
191 ctrlset
= (flags
& OSC_CONTROL_MASKS
);
195 if (ctrlset_buf
[OSC_SUPPORT_TYPE
] &&
196 ((global_ctrlsets
& ctrlset
) != ctrlset
)) {
199 ctrlset_buf
[OSC_CONTROL_TYPE
] |= ctrlset
;
200 status
= acpi_get_devices ( PCI_ROOT_HID_STRING
,
204 if (ACPI_FAILURE (status
)) {
205 ctrlset_buf
[OSC_CONTROL_TYPE
] &= ~ctrlset
;
210 EXPORT_SYMBOL(pci_osc_control_set
);
213 static int pci_acpi_find_device(struct device
*dev
, acpi_handle
*handle
)
215 struct pci_dev
* pci_dev
;
218 pci_dev
= to_pci_dev(dev
);
219 /* Please ref to ACPI spec for the syntax of _ADR */
220 addr
= (PCI_SLOT(pci_dev
->devfn
) << 16) | PCI_FUNC(pci_dev
->devfn
);
221 *handle
= acpi_get_child(DEVICE_ACPI_HANDLE(dev
->parent
), addr
);
227 static int pci_acpi_find_root_bridge(struct device
*dev
, acpi_handle
*handle
)
230 unsigned int seg
, bus
;
233 * The string should be the same as root bridge's name
234 * Please look at 'pci_scan_bus_parented'
236 num
= sscanf(dev
->bus_id
, "pci%04x:%02x", &seg
, &bus
);
239 *handle
= acpi_get_pci_rootbridge_handle(seg
, bus
);
245 static struct acpi_bus_type pci_acpi_bus
= {
246 .bus
= &pci_bus_type
,
247 .find_device
= pci_acpi_find_device
,
248 .find_bridge
= pci_acpi_find_root_bridge
,
251 static int __init
pci_acpi_init(void)
255 ret
= register_acpi_bus_type(&pci_acpi_bus
);
260 arch_initcall(pci_acpi_init
);