blob: 42cd21480833668d07d6e1a7f502ac3fe9ab6013 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -08003 * (c) Copyright 2003, 2006 Hewlett-Packard Development Company, L.P.
4 * Alex Williamson <alex.williamson@hp.com>
5 * Bjorn Helgaas <bjorn.helgaas@hp.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/module.h>
9#include <linux/types.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13#include <asm/acpi-ext.h>
14
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -080015/*
16 * Device CSRs that do not appear in PCI config space should be described
17 * via ACPI. This would normally be done with Address Space Descriptors
18 * marked as "consumer-only," but old versions of Windows and Linux ignore
19 * the producer/consumer flag, so HP invented a vendor-defined resource to
20 * describe the location and size of CSR space.
21 */
22
23struct acpi_vendor_uuid hp_ccsr_uuid = {
24 .subtype = 2,
25 .data = { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
26 0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
Linus Torvalds1da177e2005-04-16 15:20:36 -070027};
28
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -080029static acpi_status hp_ccsr_locate(acpi_handle obj, u64 *base, u64 *length)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
31 acpi_status status;
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -080032 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
33 struct acpi_resource *resource;
34 struct acpi_resource_vendor_typed *vendor;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -080036 status = acpi_get_vendor_resource(obj, METHOD_NAME__CRS, &hp_ccsr_uuid,
37 &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -080039 resource = buffer.pointer;
40 vendor = &resource->data.vendor_typed;
41
42 if (ACPI_FAILURE(status) || vendor->byte_length < 16) {
43 status = AE_NOT_FOUND;
44 goto exit;
45 }
46
47 memcpy(base, vendor->byte_data, sizeof(*base));
48 memcpy(length, vendor->byte_data + 8, sizeof(*length));
49
50 exit:
Len Brown02438d82006-06-30 03:19:10 -040051 kfree(buffer.pointer);
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -080052 return status;
53}
54
55struct csr_space {
56 u64 base;
57 u64 length;
58};
59
60static acpi_status find_csr_space(struct acpi_resource *resource, void *data)
61{
62 struct csr_space *space = data;
63 struct acpi_resource_address64 addr;
64 acpi_status status;
65
66 status = acpi_resource_to_address64(resource, &addr);
67 if (ACPI_SUCCESS(status) &&
68 addr.resource_type == ACPI_MEMORY_RANGE &&
Lv Zhenga45de932015-01-26 16:58:56 +080069 addr.address.address_length &&
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -080070 addr.producer_consumer == ACPI_CONSUMER) {
Lv Zhenga45de932015-01-26 16:58:56 +080071 space->base = addr.address.minimum;
72 space->length = addr.address.address_length;
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -080073 return AE_CTRL_TERMINATE;
74 }
75 return AE_OK; /* keep looking */
76}
77
78static acpi_status hp_crs_locate(acpi_handle obj, u64 *base, u64 *length)
79{
80 struct csr_space space = { 0, 0 };
81
82 acpi_walk_resources(obj, METHOD_NAME__CRS, find_csr_space, &space);
83 if (!space.length)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 return AE_NOT_FOUND;
85
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -080086 *base = space.base;
87 *length = space.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 return AE_OK;
89}
90
Bjorn Helgaas03fbaca2006-03-28 14:06:20 -080091acpi_status hp_acpi_csr_space(acpi_handle obj, u64 *csr_base, u64 *csr_length)
92{
93 acpi_status status;
94
95 status = hp_ccsr_locate(obj, csr_base, csr_length);
96 if (ACPI_SUCCESS(status))
97 return status;
98
99 return hp_crs_locate(obj, csr_base, csr_length);
100}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101EXPORT_SYMBOL(hp_acpi_csr_space);