]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/acpi/test.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / acpi / test.c
1 /* test.c
2  *
3  * ACPI BIOS interface test program.
4  * (C) 2011-2012 Jonathan Campbell.
5  * Hackipedia DOS library.
6  *
7  * This code is licensed under the LGPL.
8  * <insert LGPL legal text here>
9  *
10  * Compiles for intended target environments:
11  *   - MS-DOS [pure DOS mode, or Windows or OS/2 DOS Box]
12  */
13
14 #include <stdio.h>
15 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
16 #include <stdlib.h>
17 #include <stddef.h>
18 #include <string.h>
19 #include <unistd.h>
20 #include <malloc.h>
21 #include <assert.h>
22 #include <ctype.h>
23 #include <fcntl.h>
24 #include <dos.h>
25
26 #include <hw/dos/dos.h>
27 #include <hw/cpu/cpu.h>
28 #include <hw/acpi/acpi.h>
29 #include <hw/8254/8254.h>               /* 8254 timer */
30 #include <hw/8259/8259.h>               /* 8259 PIC */
31 #include <hw/flatreal/flatreal.h>
32 #include <hw/dos/doswin.h>
33
34 static void help() {
35         fprintf(stderr,"Test [options]\n");
36         fprintf(stderr,"  /32      Use 32-bit RSDT\n");
37 }
38
39 int main(int argc,char **argv) {
40         struct acpi_rsdt_header sdth;
41         acpi_memaddr_t addr;
42         unsigned long i,max;
43         uint32_t tmp32,tmplen;
44         char tmp[32];
45
46         for (i=1;i < (unsigned long)argc;) {
47                 const char *a = argv[(unsigned int)(i++)];
48
49                 if (*a == '-' || *a == '/') {
50                         do { a++; } while (*a == '-' || *a == '/');
51
52                         if (!strcmp(a,"?") || !strcmp(a,"h") || !strcmp(a,"help")) {
53                                 help();
54                                 return 1;
55                         }
56                         else if (!strcmp(a,"32")) {
57                                 acpi_use_rsdt_32 = 1;
58                         }
59                         else {
60                                 fprintf(stderr,"Unknown switch '%s'\n",a);
61                                 help();
62                                 return 1;
63                         }
64                 }
65                 else {
66                         fprintf(stderr,"Unknown arg '%s'\n",a);
67                         help();
68                         return 1;
69                 }
70         }
71
72         if (!probe_8254()) {
73                 printf("Cannot init 8254 timer\n");
74                 return 1;
75         }
76         if (!probe_8259()) {
77                 printf("Cannot init 8259 PIC\n");
78                 return 1;
79         }
80         cpu_probe();
81         probe_dos();
82         detect_windows();
83 #if TARGET_MSDOS == 32
84         probe_dpmi();
85         dos_ltp_probe();
86 #endif
87
88 #if TARGET_MSDOS == 16
89         if (!flatrealmode_setup(FLATREALMODE_4GB)) {
90                 printf("Unable to set up flat real mode (needed for 16-bit builds)\n");
91                 printf("Most ACPI functions require access to the full 4GB range.\n");
92                 return 1;
93         }
94 #endif
95
96         if (!acpi_probe()) {
97                 printf("ACPI BIOS not found\n");
98                 return 1;
99         }
100         assert(acpi_rsdp != NULL);
101         printf("ACPI %u.0 structure at 0x%05lX\n",acpi_rsdp->revision+1,(unsigned long)acpi_rsdp_location);
102
103         memcpy(tmp,(char*)(&(acpi_rsdp->OEM_id)),6); tmp[6]=0;
104         printf("ACPI OEM ID '%s', RSDT address (32-bit) 0x%08lX Length %lu\n",tmp,
105                 (unsigned long)(acpi_rsdp->rsdt_address),
106                 (unsigned long)(acpi_rsdp->length));
107         if (acpi_rsdp->revision != 0)
108                 printf("   XSDT address (64-bit) 0x%016llX\n",
109                         (unsigned long long)(acpi_rsdp->xsdt_address));
110
111         printf("Chosen RSDT/XSDT at 0x%08llX\n",(unsigned long long)acpi_rsdt_location);
112
113         if (acpi_rsdt != NULL) {
114                 memcpy(tmp,(void*)(acpi_rsdt->signature),4); tmp[4] = 0;
115                 printf("  '%s': len=%lu rev=%u\n",tmp,(unsigned long)acpi_rsdt->length,
116                         acpi_rsdt->revision);
117
118                 memcpy(tmp,(void*)(acpi_rsdt->OEM_id),6); tmp[6] = 0;
119                 printf("  OEM id: '%s'\n",tmp);
120
121                 memcpy(tmp,(void*)(acpi_rsdt->OEM_table_id),8); tmp[8] = 0;
122                 printf("  OEM table id: '%s' rev %lu\n",tmp,
123                         (unsigned long)acpi_rsdt->OEM_revision);
124
125                 memcpy(tmp,(void*)(&(acpi_rsdt->creator_id)),4); tmp[4] = 0;
126                 printf("  Creator: '%s' rev %lu\n",tmp,
127                         (unsigned long)acpi_rsdt->creator_revision);
128         }
129
130         max = acpi_rsdt_entries();
131         if (acpi_rsdt_is_xsdt()) {
132                 printf("Showing XSDT, %lu entries\n",max);
133         }
134         else {
135                 printf("Showing RSDT, %lu entries\n",max);
136         }
137
138         for (i=0;i < max;i++) {
139                 addr = acpi_rsdt_entry(i);
140                 printf(" [%lu] 0x%08llX ",i,(unsigned long long)addr);
141                 if (addr != 0ULL) {
142                         tmp32 = acpi_mem_readd(addr);
143                         tmplen = 0;
144
145                         memcpy(tmp,&tmp32,4); tmp[4] = 0;
146                         if (acpi_probe_rsdt_check(addr,tmp32,&tmplen)) {
147                                 acpi_memcpy_from_phys(&sdth,addr,sizeof(struct acpi_rsdt_header));
148
149                                 printf("'%s' len=0x%lX rev=%u ",tmp,(unsigned long)tmplen,sdth.revision);
150
151                                 memcpy(tmp,&sdth.OEM_id,6); tmp[6] = 0;
152                                 printf("OEM id: '%s'\n",tmp);
153
154                                 memcpy(tmp,&sdth.OEM_table_id,8); tmp[8] = 0;
155                                 printf("OEM table id: '%s' rev %u ",tmp,sdth.OEM_revision);
156
157                                 memcpy(tmp,&sdth.creator_id,4); tmp[4] = 0;
158                                 printf("Creator id: '%s' rev %u",tmp,sdth.creator_revision);
159
160                                 if (!memcmp(sdth.signature,"MCFG",4)) {
161                                         struct acpi_mcfg_entry entry;
162                                         uint64_t o = addr + 44;
163                                         unsigned int count;
164
165                                         printf("\nPCI Express map:");
166                                         assert(sizeof(struct acpi_mcfg_entry) == 16);
167                                         count = (unsigned int)(tmplen / sizeof(struct acpi_mcfg_entry));
168                                         while (count != 0) {
169                                                 acpi_memcpy_from_phys(&entry,o,sizeof(struct acpi_mcfg_entry));
170                                                 o += sizeof(struct acpi_mcfg_entry);
171
172                                                 /* Some bioses I test against seem to return enough for 3 but fill in only 1? */
173                                                 if (entry.base_address != 0ULL || entry.start_pci_bus_number != 0 || entry.end_pci_bus_number != 0) {
174                                                         uint64_t sz;
175
176                                                         if (entry.start_pci_bus_number > entry.end_pci_bus_number)
177                                                                 entry.start_pci_bus_number = entry.end_pci_bus_number;
178
179                                                         sz = (((unsigned long long)(entry.end_pci_bus_number - entry.start_pci_bus_number)) + 1ULL) << 20ULL;
180                                                         printf("\n  @0x%08llX-0x%08llX seg=%u bus=%u-%u",
181                                                                 (unsigned long long)entry.base_address,
182                                                                 (unsigned long long)(entry.base_address + sz - 1ULL),
183                                                                 (unsigned int)entry.pci_segment_group_number,
184                                                                 (unsigned int)entry.start_pci_bus_number,
185                                                                 (unsigned int)entry.end_pci_bus_number);
186                                                 }
187
188                                                 count--;
189                                         }
190                                 }
191                         }
192                         else {
193                                 printf("'%s' check failed",tmp);
194                         }
195                 }
196                 printf("\n");
197         }
198
199         acpi_free();
200         return 0;
201 }
202