madt.c revision 84447
1/*-
2 * Copyright (c) 2001 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/ia64/acpica/madt.c 84447 2001-10-04 08:45:19Z dfr $
27 */
28
29#include "acpi.h"
30
31#pragma pack(1)
32
33#define APIC_INTERRUPT_SOURCE_OVERRIDE 2
34#define APIC_NMI		3
35#define APIC_LOCAL_APIC_NMI	4
36#define APIC_LOCAL_APIC_OVERRIDE 5
37#define APIC_IO_SAPIC		6
38#define APIC_LOCAL_SAPIC	7
39#define APIC_PLATFORM_INTERRUPT	8
40
41
42typedef struct  /* Interrupt Source Override */
43{
44    APIC_HEADER             header;
45    UINT8                   Bus;
46    UINT8                   Source;
47    UINT32                  GlobalSystemInterrupt;
48    UINT16                  Flags;
49} INTERRUPT_SOURCE_OVERRIDE;
50
51typedef struct  /* IO SAPIC */
52{
53    APIC_HEADER             header;
54    UINT8                   IoSapicId;              /* I/O SAPIC ID */
55    UINT8                   Reserved;               /* reserved - must be zero */
56    UINT32                  Vector;                 /* interrupt vector index where INTI
57                                                     * lines start */
58    UINT64                  IoSapicAddress;         /* SAPIC's physical address */
59
60} IO_SAPIC;
61
62
63typedef struct  /* LOCAL SAPIC */
64{
65    APIC_HEADER             header;
66    UINT16                  ProcessorId;            /* ACPI processor id */
67    UINT16                  ProcessorEnabled: 1;    /* Processor is usable if set */
68    UINT16                  Reserved1       : 15;
69    UINT8                   LocalSapicId;           /* processor's local SAPIC id */
70    UINT8                   LocalSapicEid;          /* processor's local SAPIC eid */
71
72} LOCAL_SAPIC;
73
74
75typedef struct  /* PLATFORM INTERRUPT SOURCE */
76{
77    APIC_HEADER             header;
78    UINT16                  Polarity   : 2;         /* Polarity of input signal */
79    UINT16                  TriggerMode: 2;         /* Trigger mode of input signal */
80    UINT16                  Reserved1  : 12;
81    UINT8                   InterruptType;          /* 1-PMI, 2-INIT, 3-Error */
82    UINT8                   ProcessorId;            /* Processor ID of destination */
83    UINT8                   ProcessorEid;           /* Processor EID of destination */
84    UINT8                   IoSapicVector;          /* Value for redirection table */
85    UINT32                  GlobalSystemInterrupt;  /* Global System Interrupt */
86    UINT32                  Reserved2;
87
88} PLATFORM_INTERRUPT_SOURCE;
89
90
91#pragma pack()
92
93
94static void
95parse_interrupt_override(INTERRUPT_SOURCE_OVERRIDE *override)
96{
97	printf("\t\tBus=%d, Source=%d, Irq=0x%x\n",
98	       override->Bus,
99	       override->Source,
100	       override->GlobalSystemInterrupt);
101}
102
103static void
104parse_io_sapic(IO_SAPIC *sapic)
105{
106	printf("\t\tId=0x%x, Vector=0x%x, Address=0x%lx\n",
107	       sapic->IoSapicId,
108	       sapic->Vector,
109	       sapic->IoSapicAddress);
110}
111
112static void
113parse_local_sapic(LOCAL_SAPIC *sapic)
114{
115	printf("\t\tProcessorId=0x%x, Id=0x%x, Eid=0x%x\n",
116	       sapic->ProcessorId,
117	       sapic->LocalSapicId,
118	       sapic->LocalSapicEid);
119}
120
121static void
122parse_platform_interrupt(PLATFORM_INTERRUPT_SOURCE *source)
123{
124	printf("\t\tPolarity=%d, TriggerMode=%d, Id=0x%x, "
125	       "Eid=0x%x, Vector=0x%x, Irq=%d\n",
126	       source->Polarity,
127	       source->TriggerMode,
128	       source->ProcessorId,
129	       source->ProcessorEid,
130	       source->IoSapicVector,
131	       source->GlobalSystemInterrupt);
132}
133
134static void
135parse_madt(APIC_TABLE *madt)
136{
137	char			*p, *end;
138
139	/*
140	 * MADT header is followed by a number of variable length
141	 * structures.
142	 */
143	end = (char *) madt + madt->header.Length;
144	for (p = (char *) (madt + 1); p < end; ) {
145		APIC_HEADER *head = (APIC_HEADER *) p;
146
147		printf("\t");
148		switch (head->Type) {
149		case APIC_PROC:
150			if (bootverbose)
151				printf("Processor APIC entry\n");
152			break;
153
154		case APIC_IO:
155			if (bootverbose)
156				printf("I/O APIC entry\n");
157			break;
158
159		case APIC_INTERRUPT_SOURCE_OVERRIDE:
160			if (bootverbose)
161				printf("Interrupt source override entry\n");
162			parse_interrupt_override
163				((INTERRUPT_SOURCE_OVERRIDE *) head);
164			break;
165
166		case APIC_NMI:
167			if (bootverbose)
168				printf("NMI entry\n");
169			break;
170
171		case APIC_LOCAL_APIC_NMI:
172			if (bootverbose)
173				printf("Local APIC NMI entry\n");
174			break;
175
176		case APIC_LOCAL_APIC_OVERRIDE:
177			if (bootverbose)
178				printf("Local APIC override entry\n");
179			break;
180
181		case APIC_IO_SAPIC:
182			if (bootverbose)
183				printf("I/O SAPIC entry\n");
184			parse_io_sapic((IO_SAPIC *) head);
185			break;
186
187		case APIC_LOCAL_SAPIC:
188			if (bootverbose)
189				printf("Local SAPIC entry\n");
190			parse_local_sapic((LOCAL_SAPIC *) head);
191			break;
192
193		case APIC_PLATFORM_INTERRUPT:
194			if (bootverbose)
195				printf("Platform interrupt entry\n");
196			parse_platform_interrupt
197				((PLATFORM_INTERRUPT_SOURCE *) head);
198			break;
199
200		default:
201			if (bootverbose)
202				printf("Unknown type %d entry\n", head->Type);
203			break;
204		}
205
206		p = p + head->Length;
207	}
208}
209
210void
211ia64_parse_xsdt(XSDT_DESCRIPTOR *xsdt)
212{
213	int			i, count;
214	ACPI_TABLE_HEADER	*table;
215
216	/*
217	 * First find the MADT.
218	 */
219	count = (UINT64 *) ((char *) xsdt + xsdt->Header.Length)
220		- &xsdt->TableOffsetEntry[0];
221	for (i = 0; i < count; i++) {
222		table = (ACPI_TABLE_HEADER *)
223			IA64_PHYS_TO_RR7(xsdt->TableOffsetEntry[i]);
224		if (bootverbose)
225			printf("Table '%c%c%c%c' at %p\n",
226			       table->Signature[0],
227			       table->Signature[1],
228			       table->Signature[2],
229			       table->Signature[3],
230			       table);
231		if (!strncmp(table->Signature, APIC_SIG, 4)) {
232			parse_madt((APIC_TABLE *) table);
233		}
234	}
235}
236