blob: 4a5574ff007b8a1f1d5b0205d417c936b86e23f6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/ia64/kernel/acpi-ext.c
3 *
4 * Copyright (C) 2003 Hewlett-Packard
5 * Copyright (C) Alex Williamson
6 * Copyright (C) Bjorn Helgaas
7 *
8 * Vendor specific extensions to ACPI.
9 */
10
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/acpi.h>
15#include <linux/efi.h>
16
17#include <asm/acpi-ext.h>
18
19struct acpi_vendor_descriptor {
Len Brown4be44fc2005-08-05 00:44:28 -040020 u8 guid_id;
21 efi_guid_t guid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022};
23
24struct acpi_vendor_info {
Len Brown4be44fc2005-08-05 00:44:28 -040025 struct acpi_vendor_descriptor *descriptor;
26 u8 *data;
27 u32 length;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028};
29
30acpi_status
31acpi_vendor_resource_match(struct acpi_resource *resource, void *context)
32{
Len Brown4be44fc2005-08-05 00:44:28 -040033 struct acpi_vendor_info *info = (struct acpi_vendor_info *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 struct acpi_resource_vendor *vendor;
35 struct acpi_vendor_descriptor *descriptor;
Bob Moore50eca3e2005-09-30 19:03:00 -040036 u32 byte_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Bob Moore50eca3e2005-09-30 19:03:00 -040038 if (resource->type != ACPI_RESOURCE_TYPE_VENDOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 return AE_OK;
40
Len Brown4be44fc2005-08-05 00:44:28 -040041 vendor = (struct acpi_resource_vendor *)&resource->data;
Bob Moore50eca3e2005-09-30 19:03:00 -040042 descriptor = (struct acpi_vendor_descriptor *)vendor->byte_data;
43 if (vendor->byte_length <= sizeof(*info->descriptor) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 descriptor->guid_id != info->descriptor->guid_id ||
45 efi_guidcmp(descriptor->guid, info->descriptor->guid))
46 return AE_OK;
47
Bob Moore50eca3e2005-09-30 19:03:00 -040048 byte_length = vendor->byte_length - sizeof(struct acpi_vendor_descriptor);
49 info->data = acpi_os_allocate(byte_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 if (!info->data)
51 return AE_NO_MEMORY;
52
Len Brown4be44fc2005-08-05 00:44:28 -040053 memcpy(info->data,
Bob Moore50eca3e2005-09-30 19:03:00 -040054 vendor->byte_data + sizeof(struct acpi_vendor_descriptor),
55 byte_length);
56 info->length = byte_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 return AE_CTRL_TERMINATE;
58}
59
60acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040061acpi_find_vendor_resource(acpi_handle obj, struct acpi_vendor_descriptor * id,
Bob Moore50eca3e2005-09-30 19:03:00 -040062 u8 ** data, u32 * byte_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 struct acpi_vendor_info info;
65
66 info.descriptor = id;
67 info.data = NULL;
68
Len Brown4be44fc2005-08-05 00:44:28 -040069 acpi_walk_resources(obj, METHOD_NAME__CRS, acpi_vendor_resource_match,
70 &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 if (!info.data)
72 return AE_NOT_FOUND;
73
74 *data = info.data;
Bob Moore50eca3e2005-09-30 19:03:00 -040075 *byte_length = info.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 return AE_OK;
77}
78
79struct acpi_vendor_descriptor hp_ccsr_descriptor = {
80 .guid_id = 2,
Len Brown4be44fc2005-08-05 00:44:28 -040081 .guid =
82 EFI_GUID(0x69e9adf9, 0x924f, 0xab5f, 0xf6, 0x4a, 0x24, 0xd2, 0x01,
83 0x37, 0x0e, 0xad)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084};
85
Len Brown4be44fc2005-08-05 00:44:28 -040086acpi_status hp_acpi_csr_space(acpi_handle obj, u64 * csr_base, u64 * csr_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
88 acpi_status status;
89 u8 *data;
90 u32 length;
91
Len Brown4be44fc2005-08-05 00:44:28 -040092 status =
93 acpi_find_vendor_resource(obj, &hp_ccsr_descriptor, &data, &length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 if (ACPI_FAILURE(status) || length != 16)
96 return AE_NOT_FOUND;
97
98 memcpy(csr_base, data, sizeof(*csr_base));
99 memcpy(csr_length, data + 8, sizeof(*csr_length));
100 acpi_os_free(data);
101
102 return AE_OK;
103}
104
105EXPORT_SYMBOL(hp_acpi_csr_space);