| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Bjorn Helgaas | 03fbaca | 2006-03-28 14:06:20 -0800 | [diff] [blame] | 2 | * (c) Copyright 2003, 2006 Hewlett-Packard Development Company, L.P. | 
|  | 3 | *	Alex Williamson <alex.williamson@hp.com> | 
|  | 4 | *	Bjorn Helgaas <bjorn.helgaas@hp.com> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * | 
| Bjorn Helgaas | 03fbaca | 2006-03-28 14:06:20 -0800 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify | 
|  | 7 | * it under the terms of the GNU General Public License version 2 as | 
|  | 8 | * published by the Free Software Foundation. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ | 
|  | 10 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> | 
|  | 12 | #include <linux/types.h> | 
|  | 13 | #include <linux/acpi.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 |  | 
|  | 15 | #include <asm/acpi-ext.h> | 
|  | 16 |  | 
| Bjorn Helgaas | 03fbaca | 2006-03-28 14:06:20 -0800 | [diff] [blame] | 17 | /* | 
|  | 18 | * Device CSRs that do not appear in PCI config space should be described | 
|  | 19 | * via ACPI.  This would normally be done with Address Space Descriptors | 
|  | 20 | * marked as "consumer-only," but old versions of Windows and Linux ignore | 
|  | 21 | * the producer/consumer flag, so HP invented a vendor-defined resource to | 
|  | 22 | * describe the location and size of CSR space. | 
|  | 23 | */ | 
|  | 24 |  | 
|  | 25 | struct acpi_vendor_uuid hp_ccsr_uuid = { | 
|  | 26 | .subtype = 2, | 
|  | 27 | .data = { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a, | 
|  | 28 | 0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad }, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | }; | 
|  | 30 |  | 
| Bjorn Helgaas | 03fbaca | 2006-03-28 14:06:20 -0800 | [diff] [blame] | 31 | static acpi_status hp_ccsr_locate(acpi_handle obj, u64 *base, u64 *length) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { | 
|  | 33 | acpi_status status; | 
| Bjorn Helgaas | 03fbaca | 2006-03-28 14:06:20 -0800 | [diff] [blame] | 34 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 
|  | 35 | struct acpi_resource *resource; | 
|  | 36 | struct acpi_resource_vendor_typed *vendor; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 |  | 
| Bjorn Helgaas | 03fbaca | 2006-03-28 14:06:20 -0800 | [diff] [blame] | 38 | status = acpi_get_vendor_resource(obj, METHOD_NAME__CRS, &hp_ccsr_uuid, | 
|  | 39 | &buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 |  | 
| Bjorn Helgaas | 03fbaca | 2006-03-28 14:06:20 -0800 | [diff] [blame] | 41 | resource = buffer.pointer; | 
|  | 42 | vendor = &resource->data.vendor_typed; | 
|  | 43 |  | 
|  | 44 | if (ACPI_FAILURE(status) || vendor->byte_length < 16) { | 
|  | 45 | status = AE_NOT_FOUND; | 
|  | 46 | goto exit; | 
|  | 47 | } | 
|  | 48 |  | 
|  | 49 | memcpy(base, vendor->byte_data, sizeof(*base)); | 
|  | 50 | memcpy(length, vendor->byte_data + 8, sizeof(*length)); | 
|  | 51 |  | 
|  | 52 | exit: | 
| Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 53 | kfree(buffer.pointer); | 
| Bjorn Helgaas | 03fbaca | 2006-03-28 14:06:20 -0800 | [diff] [blame] | 54 | return status; | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | struct csr_space { | 
|  | 58 | u64	base; | 
|  | 59 | u64	length; | 
|  | 60 | }; | 
|  | 61 |  | 
|  | 62 | static acpi_status find_csr_space(struct acpi_resource *resource, void *data) | 
|  | 63 | { | 
|  | 64 | struct csr_space *space = data; | 
|  | 65 | struct acpi_resource_address64 addr; | 
|  | 66 | acpi_status status; | 
|  | 67 |  | 
|  | 68 | status = acpi_resource_to_address64(resource, &addr); | 
|  | 69 | if (ACPI_SUCCESS(status) && | 
|  | 70 | addr.resource_type == ACPI_MEMORY_RANGE && | 
|  | 71 | addr.address_length && | 
|  | 72 | addr.producer_consumer == ACPI_CONSUMER) { | 
|  | 73 | space->base = addr.minimum; | 
|  | 74 | space->length = addr.address_length; | 
|  | 75 | return AE_CTRL_TERMINATE; | 
|  | 76 | } | 
|  | 77 | return AE_OK;		/* keep looking */ | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | static acpi_status hp_crs_locate(acpi_handle obj, u64 *base, u64 *length) | 
|  | 81 | { | 
|  | 82 | struct csr_space space = { 0, 0 }; | 
|  | 83 |  | 
|  | 84 | acpi_walk_resources(obj, METHOD_NAME__CRS, find_csr_space, &space); | 
|  | 85 | if (!space.length) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | return AE_NOT_FOUND; | 
|  | 87 |  | 
| Bjorn Helgaas | 03fbaca | 2006-03-28 14:06:20 -0800 | [diff] [blame] | 88 | *base = space.base; | 
|  | 89 | *length = space.length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | return AE_OK; | 
|  | 91 | } | 
|  | 92 |  | 
| Bjorn Helgaas | 03fbaca | 2006-03-28 14:06:20 -0800 | [diff] [blame] | 93 | acpi_status hp_acpi_csr_space(acpi_handle obj, u64 *csr_base, u64 *csr_length) | 
|  | 94 | { | 
|  | 95 | acpi_status status; | 
|  | 96 |  | 
|  | 97 | status = hp_ccsr_locate(obj, csr_base, csr_length); | 
|  | 98 | if (ACPI_SUCCESS(status)) | 
|  | 99 | return status; | 
|  | 100 |  | 
|  | 101 | return hp_crs_locate(obj, csr_base, csr_length); | 
|  | 102 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | EXPORT_SYMBOL(hp_acpi_csr_space); |