ia64/xen-unstable

view tools/firmware/vmxassist/acpi_madt.c @ 6979:f8e7af29daa1

merge?
author cl349@firebug.cl.cam.ac.uk
date Tue Sep 20 09:43:46 2005 +0000 (2005-09-20)
parents 739154e26fb7
children 06d84bf87159
line source
1 /*
2 * acpi_madt.c: Update ACPI MADT table for multiple processor guest.
3 *
4 * Yu Ke, ke.yu@intel.com
5 * Copyright (c) 2005, Intel Corporation.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 * Place - Suite 330, Boston, MA 02111-1307 USA.
19 */
20 #include "../acpi/acpi2_0.h"
21 #include "../acpi/acpi_madt.h"
23 #define NULL ((void*)0)
25 extern int puts(const char *s);
27 #define VCPU_MAGIC 0x76637075 /* "vcpu" */
29 /* xc_vmx_builder wrote vcpu block at 0x9F800. Return it. */
30 static int
31 get_vcpus(void)
32 {
33 unsigned long *vcpus;
35 vcpus = (unsigned long *)0x9F800;
36 if (vcpus[0] != VCPU_MAGIC) {
37 puts("Bad vcpus magic, set vcpu number=1\n");
38 return 1;
39 }
41 return vcpus[1];
42 }
44 static void *
45 acpi_madt_get_madt(unsigned char *acpi_start)
46 {
47 ACPI_2_0_RSDP *rsdp=NULL;
48 ACPI_2_0_RSDT *rsdt=NULL;
49 ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE *madt;
51 rsdp = (ACPI_2_0_RSDP *)(acpi_start + sizeof(ACPI_2_0_FACS));
52 if (rsdp->Signature != ACPI_2_0_RSDP_SIGNATURE) {
53 puts("Bad RSDP signature\n");
54 return NULL;
55 }
57 rsdt= (ACPI_2_0_RSDT *)
58 (acpi_start + rsdp->RsdtAddress - ACPI_PHYSICAL_ADDRESS);
59 if (rsdt->Header.Signature != ACPI_2_0_RSDT_SIGNATURE) {
60 puts("Bad RSDT signature\n");
61 return NULL;
62 }
64 madt = (ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE *)
65 ( acpi_start+ rsdt->Entry[1] - ACPI_PHYSICAL_ADDRESS);
66 if (madt->Header.Header.Signature !=
67 ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE) {
68 puts("Bad MADT signature \n");
69 return NULL;
70 }
72 return madt;
73 }
75 static void
76 set_checksum(void *start, int checksum_offset, int len)
77 {
78 unsigned char sum = 0;
79 unsigned char *ptr;
81 ptr = start;
82 ptr[checksum_offset] = 0;
83 while (len--)
84 sum += *ptr++;
86 ptr = start;
87 ptr[checksum_offset] = -sum;
88 }
90 static int
91 acpi_madt_set_local_apics(
92 int nr_vcpu,
93 ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE *madt)
94 {
95 int i;
97 if ((nr_vcpu > MAX_VIRT_CPUS) || (nr_vcpu < 0) || !madt)
98 return -1;
100 for (i = 0; i < nr_vcpu; i++) {
101 madt->LocalApic[i].Type = ACPI_PROCESSOR_LOCAL_APIC;
102 madt->LocalApic[i].Length = sizeof (ACPI_LOCAL_APIC_STRUCTURE);
103 madt->LocalApic[i].AcpiProcessorId = i;
104 madt->LocalApic[i].ApicId = i;
105 madt->LocalApic[i].Flags = 1;
106 }
108 madt->Header.Header.Length =
109 sizeof(ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE) -
110 (MAX_VIRT_CPUS - nr_vcpu)* sizeof(ACPI_LOCAL_APIC_STRUCTURE);
112 return 0;
113 }
115 #define FIELD_OFFSET(TYPE,Field) ((unsigned int)(&(((TYPE *) 0)->Field)))
117 int acpi_madt_update(unsigned char *acpi_start)
118 {
119 int rc;
120 ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE *madt;
122 madt = acpi_madt_get_madt(acpi_start);
123 if (!madt)
124 return -1;
126 rc = acpi_madt_set_local_apics(get_vcpus(), madt);
127 if (rc != 0)
128 return rc;
130 set_checksum(
131 madt, FIELD_OFFSET(ACPI_TABLE_HEADER, Checksum),
132 madt->Header.Header.Length);
134 return 0;
135 }
137 /*
138 * Local variables:
139 * c-file-style: "linux"
140 * indent-tabs-mode: t
141 * c-indent-level: 8
142 * c-basic-offset: 8
143 * tab-width: 8
144 * End:
145 */