acpi_table.c revision 1.1.2.2 1 1.1.2.2 pgoyette /* $NetBSD: acpi_table.c,v 1.1.2.2 2018/10/20 06:58:24 pgoyette Exp $ */
2 1.1.2.2 pgoyette
3 1.1.2.2 pgoyette /*-
4 1.1.2.2 pgoyette * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 1.1.2.2 pgoyette * All rights reserved.
6 1.1.2.2 pgoyette *
7 1.1.2.2 pgoyette * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 pgoyette * by Jared McNeill <jmcneill (at) invisible.ca>.
9 1.1.2.2 pgoyette *
10 1.1.2.2 pgoyette * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 pgoyette * modification, are permitted provided that the following conditions
12 1.1.2.2 pgoyette * are met:
13 1.1.2.2 pgoyette * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 pgoyette * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 pgoyette * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 pgoyette * documentation and/or other materials provided with the distribution.
18 1.1.2.2 pgoyette *
19 1.1.2.2 pgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.2.2 pgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.2.2 pgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.2.2 pgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.2.2 pgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.2.2 pgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.2.2 pgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.2.2 pgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.2.2 pgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.2.2 pgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.2.2 pgoyette * POSSIBILITY OF SUCH DAMAGE.
30 1.1.2.2 pgoyette */
31 1.1.2.2 pgoyette
32 1.1.2.2 pgoyette /*
33 1.1.2.2 pgoyette * ACPI table functions for use in early boot before ACPICA can be safely
34 1.1.2.2 pgoyette * initialized.
35 1.1.2.2 pgoyette */
36 1.1.2.2 pgoyette
37 1.1.2.2 pgoyette #include <sys/cdefs.h>
38 1.1.2.2 pgoyette __KERNEL_RCSID(0, "$NetBSD: acpi_table.c,v 1.1.2.2 2018/10/20 06:58:24 pgoyette Exp $");
39 1.1.2.2 pgoyette
40 1.1.2.2 pgoyette #include <sys/param.h>
41 1.1.2.2 pgoyette #include <sys/bus.h>
42 1.1.2.2 pgoyette #include <sys/cpu.h>
43 1.1.2.2 pgoyette #include <sys/device.h>
44 1.1.2.2 pgoyette
45 1.1.2.2 pgoyette #include <uvm/uvm_extern.h>
46 1.1.2.2 pgoyette
47 1.1.2.2 pgoyette #include <dev/acpi/acpireg.h>
48 1.1.2.2 pgoyette #include <dev/acpi/acpivar.h>
49 1.1.2.2 pgoyette
50 1.1.2.2 pgoyette #include <machine/acpi_machdep.h>
51 1.1.2.2 pgoyette
52 1.1.2.2 pgoyette #include <arch/arm/acpi/acpi_table.h>
53 1.1.2.2 pgoyette
54 1.1.2.2 pgoyette ACPI_STATUS
55 1.1.2.2 pgoyette acpi_table_map(ACPI_PHYSICAL_ADDRESS pa, void **hdrp)
56 1.1.2.2 pgoyette {
57 1.1.2.2 pgoyette ACPI_TABLE_HEADER *header;
58 1.1.2.2 pgoyette ACPI_STATUS rv;
59 1.1.2.2 pgoyette UINT32 length;
60 1.1.2.2 pgoyette
61 1.1.2.2 pgoyette rv = acpi_md_OsMapMemory(pa, sizeof(*header), (void **)&header);
62 1.1.2.2 pgoyette if (ACPI_FAILURE(rv))
63 1.1.2.2 pgoyette return rv;
64 1.1.2.2 pgoyette length = header->Length;
65 1.1.2.2 pgoyette acpi_md_OsUnmapMemory(header, sizeof(*header));
66 1.1.2.2 pgoyette
67 1.1.2.2 pgoyette return acpi_md_OsMapMemory(pa, length, hdrp);
68 1.1.2.2 pgoyette }
69 1.1.2.2 pgoyette
70 1.1.2.2 pgoyette void
71 1.1.2.2 pgoyette acpi_table_unmap(ACPI_TABLE_HEADER *hdrp)
72 1.1.2.2 pgoyette {
73 1.1.2.2 pgoyette acpi_md_OsUnmapMemory(hdrp, hdrp->Length);
74 1.1.2.2 pgoyette }
75 1.1.2.2 pgoyette
76 1.1.2.2 pgoyette ACPI_STATUS
77 1.1.2.2 pgoyette acpi_table_find(const char *sig, void **hdrp)
78 1.1.2.2 pgoyette {
79 1.1.2.2 pgoyette ACPI_TABLE_RSDP *rsdp;
80 1.1.2.2 pgoyette ACPI_TABLE_XSDT *xsdt;
81 1.1.2.2 pgoyette ACPI_TABLE_HEADER *header;
82 1.1.2.2 pgoyette ACPI_PHYSICAL_ADDRESS pa;
83 1.1.2.2 pgoyette ACPI_STATUS rv;
84 1.1.2.2 pgoyette
85 1.1.2.2 pgoyette /* RDSP contains a pointer to the XSDT */
86 1.1.2.2 pgoyette pa = 0;
87 1.1.2.2 pgoyette rv = acpi_md_OsMapMemory(acpi_md_OsGetRootPointer(), sizeof(*rsdp), (void **)&rsdp);
88 1.1.2.2 pgoyette if (ACPI_FAILURE(rv))
89 1.1.2.2 pgoyette return rv;
90 1.1.2.2 pgoyette if (memcmp(rsdp->Signature, ACPI_SIG_RSDP, sizeof(rsdp->Signature)) == 0)
91 1.1.2.2 pgoyette pa = rsdp->XsdtPhysicalAddress;
92 1.1.2.2 pgoyette acpi_md_OsUnmapMemory(rsdp, sizeof(*rsdp));
93 1.1.2.2 pgoyette if (pa == 0)
94 1.1.2.2 pgoyette return AE_NOT_FOUND;
95 1.1.2.2 pgoyette
96 1.1.2.2 pgoyette /* XSDT contains pointers to other tables */
97 1.1.2.2 pgoyette rv = acpi_table_map(pa, (void **)&xsdt);
98 1.1.2.2 pgoyette if (ACPI_FAILURE(rv))
99 1.1.2.2 pgoyette return rv;
100 1.1.2.2 pgoyette const u_int entries = (xsdt->Header.Length - sizeof(ACPI_TABLE_HEADER)) / ACPI_XSDT_ENTRY_SIZE;
101 1.1.2.2 pgoyette for (u_int n = 0; n < entries; n++) {
102 1.1.2.2 pgoyette rv = acpi_table_map(xsdt->TableOffsetEntry[n], (void **)&header);
103 1.1.2.2 pgoyette if (ACPI_FAILURE(rv))
104 1.1.2.2 pgoyette continue;
105 1.1.2.2 pgoyette if (memcmp(header->Signature, sig, sizeof(header->Signature)) == 0) {
106 1.1.2.2 pgoyette acpi_table_unmap((ACPI_TABLE_HEADER *)xsdt);
107 1.1.2.2 pgoyette *hdrp = header;
108 1.1.2.2 pgoyette return AE_OK;
109 1.1.2.2 pgoyette }
110 1.1.2.2 pgoyette }
111 1.1.2.2 pgoyette
112 1.1.2.2 pgoyette /* Not found */
113 1.1.2.2 pgoyette acpi_table_unmap((ACPI_TABLE_HEADER *)xsdt);
114 1.1.2.2 pgoyette return AE_NOT_FOUND;
115 1.1.2.2 pgoyette }
116