Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  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>
 
 
 
 
  6 */
  7
  8#include <linux/module.h>
  9#include <linux/types.h>
 10#include <linux/slab.h>
 11#include <linux/acpi.h>
 12
 13#include <asm/acpi-ext.h>
 14
 15/*
 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 },
 27};
 28
 29static acpi_status hp_ccsr_locate(acpi_handle obj, u64 *base, u64 *length)
 30{
 31	acpi_status status;
 32	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 33	struct acpi_resource *resource;
 34	struct acpi_resource_vendor_typed *vendor;
 35
 36	status = acpi_get_vendor_resource(obj, METHOD_NAME__CRS, &hp_ccsr_uuid,
 37		&buffer);
 38
 39	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:
 51	kfree(buffer.pointer);
 52	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 &&
 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;
 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)
 84		return AE_NOT_FOUND;
 85
 86	*base = space.base;
 87	*length = space.length;
 88	return AE_OK;
 89}
 90
 91acpi_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}
101EXPORT_SYMBOL(hp_acpi_csr_space);
v3.15
 
  1/*
  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>
  5 *
  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.
  9 */
 10
 11#include <linux/module.h>
 12#include <linux/types.h>
 13#include <linux/slab.h>
 14#include <linux/acpi.h>
 15
 16#include <asm/acpi-ext.h>
 17
 18/*
 19 * Device CSRs that do not appear in PCI config space should be described
 20 * via ACPI.  This would normally be done with Address Space Descriptors
 21 * marked as "consumer-only," but old versions of Windows and Linux ignore
 22 * the producer/consumer flag, so HP invented a vendor-defined resource to
 23 * describe the location and size of CSR space.
 24 */
 25
 26struct acpi_vendor_uuid hp_ccsr_uuid = {
 27	.subtype = 2,
 28	.data = { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
 29	    0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
 30};
 31
 32static acpi_status hp_ccsr_locate(acpi_handle obj, u64 *base, u64 *length)
 33{
 34	acpi_status status;
 35	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 36	struct acpi_resource *resource;
 37	struct acpi_resource_vendor_typed *vendor;
 38
 39	status = acpi_get_vendor_resource(obj, METHOD_NAME__CRS, &hp_ccsr_uuid,
 40		&buffer);
 41
 42	resource = buffer.pointer;
 43	vendor = &resource->data.vendor_typed;
 44
 45	if (ACPI_FAILURE(status) || vendor->byte_length < 16) {
 46		status = AE_NOT_FOUND;
 47		goto exit;
 48	}
 49
 50	memcpy(base, vendor->byte_data, sizeof(*base));
 51	memcpy(length, vendor->byte_data + 8, sizeof(*length));
 52
 53  exit:
 54	kfree(buffer.pointer);
 55	return status;
 56}
 57
 58struct csr_space {
 59	u64	base;
 60	u64	length;
 61};
 62
 63static acpi_status find_csr_space(struct acpi_resource *resource, void *data)
 64{
 65	struct csr_space *space = data;
 66	struct acpi_resource_address64 addr;
 67	acpi_status status;
 68
 69	status = acpi_resource_to_address64(resource, &addr);
 70	if (ACPI_SUCCESS(status) &&
 71	    addr.resource_type == ACPI_MEMORY_RANGE &&
 72	    addr.address_length &&
 73	    addr.producer_consumer == ACPI_CONSUMER) {
 74		space->base = addr.minimum;
 75		space->length = addr.address_length;
 76		return AE_CTRL_TERMINATE;
 77	}
 78	return AE_OK;		/* keep looking */
 79}
 80
 81static acpi_status hp_crs_locate(acpi_handle obj, u64 *base, u64 *length)
 82{
 83	struct csr_space space = { 0, 0 };
 84
 85	acpi_walk_resources(obj, METHOD_NAME__CRS, find_csr_space, &space);
 86	if (!space.length)
 87		return AE_NOT_FOUND;
 88
 89	*base = space.base;
 90	*length = space.length;
 91	return AE_OK;
 92}
 93
 94acpi_status hp_acpi_csr_space(acpi_handle obj, u64 *csr_base, u64 *csr_length)
 95{
 96	acpi_status status;
 97
 98	status = hp_ccsr_locate(obj, csr_base, csr_length);
 99	if (ACPI_SUCCESS(status))
100		return status;
101
102	return hp_crs_locate(obj, csr_base, csr_length);
103}
104EXPORT_SYMBOL(hp_acpi_csr_space);