Blame view

arch/ia64/kernel/acpi-ext.c 2.73 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
03fbaca36   Bjorn Helgaas   [IA64] update HP ...
2
3
4
   * (c) Copyright 2003, 2006 Hewlett-Packard Development Company, L.P.
   *	Alex Williamson <alex.williamson@hp.com>
   *	Bjorn Helgaas <bjorn.helgaas@hp.com>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
   *
03fbaca36   Bjorn Helgaas   [IA64] update HP ...
6
7
8
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
  #include <linux/module.h>
  #include <linux/types.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
12
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
  #include <linux/acpi.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
  
  #include <asm/acpi-ext.h>
03fbaca36   Bjorn Helgaas   [IA64] update HP ...
16
17
18
19
20
21
22
  /*
   * Device CSRs that do not appear in PCI config space should be described
   * via ACPI.  This would normally be done with Address Space Descriptors
   * marked as "consumer-only," but old versions of Windows and Linux ignore
   * the producer/consumer flag, so HP invented a vendor-defined resource to
   * describe the location and size of CSR space.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23

03fbaca36   Bjorn Helgaas   [IA64] update HP ...
24
25
26
27
  struct acpi_vendor_uuid hp_ccsr_uuid = {
  	.subtype = 2,
  	.data = { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
  	    0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
  };
03fbaca36   Bjorn Helgaas   [IA64] update HP ...
29
  static acpi_status hp_ccsr_locate(acpi_handle obj, u64 *base, u64 *length)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  {
03fbaca36   Bjorn Helgaas   [IA64] update HP ...
31
32
33
34
  	acpi_status status;
  	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  	struct acpi_resource *resource;
  	struct acpi_resource_vendor_typed *vendor;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35

03fbaca36   Bjorn Helgaas   [IA64] update HP ...
36
37
  	status = acpi_get_vendor_resource(obj, METHOD_NAME__CRS, &hp_ccsr_uuid,
  		&buffer);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38

03fbaca36   Bjorn Helgaas   [IA64] update HP ...
39
40
  	resource = buffer.pointer;
  	vendor = &resource->data.vendor_typed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41

03fbaca36   Bjorn Helgaas   [IA64] update HP ...
42
43
44
45
  	if (ACPI_FAILURE(status) || vendor->byte_length < 16) {
  		status = AE_NOT_FOUND;
  		goto exit;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46

03fbaca36   Bjorn Helgaas   [IA64] update HP ...
47
48
49
50
  	memcpy(base, vendor->byte_data, sizeof(*base));
  	memcpy(length, vendor->byte_data + 8, sizeof(*length));
  
    exit:
02438d877   Len Brown   ACPI: delete acpi...
51
  	kfree(buffer.pointer);
03fbaca36   Bjorn Helgaas   [IA64] update HP ...
52
  	return status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
  }
03fbaca36   Bjorn Helgaas   [IA64] update HP ...
54
55
56
  struct csr_space {
  	u64	base;
  	u64	length;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
  };
03fbaca36   Bjorn Helgaas   [IA64] update HP ...
58
  static acpi_status find_csr_space(struct acpi_resource *resource, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
  {
03fbaca36   Bjorn Helgaas   [IA64] update HP ...
60
61
  	struct csr_space *space = data;
  	struct acpi_resource_address64 addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
  	acpi_status status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63

03fbaca36   Bjorn Helgaas   [IA64] update HP ...
64
65
66
67
68
69
70
71
72
73
74
  	status = acpi_resource_to_address64(resource, &addr);
  	if (ACPI_SUCCESS(status) &&
  	    addr.resource_type == ACPI_MEMORY_RANGE &&
  	    addr.address_length &&
  	    addr.producer_consumer == ACPI_CONSUMER) {
  		space->base = addr.minimum;
  		space->length = addr.address_length;
  		return AE_CTRL_TERMINATE;
  	}
  	return AE_OK;		/* keep looking */
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75

03fbaca36   Bjorn Helgaas   [IA64] update HP ...
76
77
78
  static acpi_status hp_crs_locate(acpi_handle obj, u64 *base, u64 *length)
  {
  	struct csr_space space = { 0, 0 };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79

03fbaca36   Bjorn Helgaas   [IA64] update HP ...
80
81
82
  	acpi_walk_resources(obj, METHOD_NAME__CRS, find_csr_space, &space);
  	if (!space.length)
  		return AE_NOT_FOUND;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83

03fbaca36   Bjorn Helgaas   [IA64] update HP ...
84
85
  	*base = space.base;
  	*length = space.length;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
87
  	return AE_OK;
  }
03fbaca36   Bjorn Helgaas   [IA64] update HP ...
88
89
90
91
92
93
94
95
96
97
  acpi_status hp_acpi_csr_space(acpi_handle obj, u64 *csr_base, u64 *csr_length)
  {
  	acpi_status status;
  
  	status = hp_ccsr_locate(obj, csr_base, csr_length);
  	if (ACPI_SUCCESS(status))
  		return status;
  
  	return hp_crs_locate(obj, csr_base, csr_length);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
  EXPORT_SYMBOL(hp_acpi_csr_space);