1 // SPDX-License-Identifier: GPL-2.0-only
3 * (c) Copyright 2003, 2006 Hewlett-Packard Development Company, L.P.
4 * Alex Williamson <alex.williamson@hp.com>
5 * Bjorn Helgaas <bjorn.helgaas@hp.com>
8 #include <linux/module.h>
9 #include <linux/types.h>
10 #include <linux/slab.h>
11 #include <linux/acpi.h>
13 #include <asm/acpi-ext.h>
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.
23 struct acpi_vendor_uuid hp_ccsr_uuid
= {
25 .data
= { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
26 0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
29 static acpi_status
hp_ccsr_locate(acpi_handle obj
, u64
*base
, u64
*length
)
32 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
33 struct acpi_resource
*resource
;
34 struct acpi_resource_vendor_typed
*vendor
;
36 status
= acpi_get_vendor_resource(obj
, METHOD_NAME__CRS
, &hp_ccsr_uuid
,
39 resource
= buffer
.pointer
;
40 vendor
= &resource
->data
.vendor_typed
;
42 if (ACPI_FAILURE(status
) || vendor
->byte_length
< 16) {
43 status
= AE_NOT_FOUND
;
47 memcpy(base
, vendor
->byte_data
, sizeof(*base
));
48 memcpy(length
, vendor
->byte_data
+ 8, sizeof(*length
));
51 kfree(buffer
.pointer
);
60 static acpi_status
find_csr_space(struct acpi_resource
*resource
, void *data
)
62 struct csr_space
*space
= data
;
63 struct acpi_resource_address64 addr
;
66 status
= acpi_resource_to_address64(resource
, &addr
);
67 if (ACPI_SUCCESS(status
) &&
68 addr
.resource_type
== ACPI_MEMORY_RANGE
&&
69 addr
.address
.address_length
&&
70 addr
.producer_consumer
== ACPI_CONSUMER
) {
71 space
->base
= addr
.address
.minimum
;
72 space
->length
= addr
.address
.address_length
;
73 return AE_CTRL_TERMINATE
;
75 return AE_OK
; /* keep looking */
78 static acpi_status
hp_crs_locate(acpi_handle obj
, u64
*base
, u64
*length
)
80 struct csr_space space
= { 0, 0 };
82 acpi_walk_resources(obj
, METHOD_NAME__CRS
, find_csr_space
, &space
);
87 *length
= space
.length
;
91 acpi_status
hp_acpi_csr_space(acpi_handle obj
, u64
*csr_base
, u64
*csr_length
)
95 status
= hp_ccsr_locate(obj
, csr_base
, csr_length
);
96 if (ACPI_SUCCESS(status
))
99 return hp_crs_locate(obj
, csr_base
, csr_length
);
101 EXPORT_SYMBOL(hp_acpi_csr_space
);