From: Joshua Wise Date: Fri, 19 Sep 2008 19:35:28 +0000 (-0400) Subject: add a first cut at a SMI API -- not many features... X-Git-Url: http://git.joshuawise.com/netwatch.git/commitdiff_plain/85bc8ca6a317e9ce0a3ce1bf27a31df11f44ac47?hp=94d78d15691f3e6ac4c4797bb21ffcf8f9cc4a39 add a first cut at a SMI API -- not many features... --- diff --git a/aseg/Makefile b/aseg/Makefile index 5033a55..a43a1f2 100644 --- a/aseg/Makefile +++ b/aseg/Makefile @@ -1,6 +1,6 @@ CC=gcc CFLAGS=-I../include -I../include/raw -nostdlib -nostdinc -fno-builtin -D__RAW__ -OBJS=counter.o firstrun.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o +OBJS=counter.o firstrun.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o ../ich2/smi.o all: aseg.elf diff --git a/aseg/counter.c b/aseg/counter.c index e4b5eae..f77d256 100644 --- a/aseg/counter.c +++ b/aseg/counter.c @@ -62,7 +62,7 @@ void pci_dump() { cts = inl(0x84C); outl(0x848, 0x0); - + outl(0x840, 0x0); switch(cts&0xF0000) { case 0x20000: @@ -95,6 +95,9 @@ void pci_dump() { default: dolog("Unhandled PCI cycle"); } + + outl(0x848, 0x1000); + outl(0x840, 0x0100); } void __start (void) @@ -126,15 +129,13 @@ void __start (void) if (inl(0x844) & 0x1000) /* devact_sts */ { pci_dump(); - outl(0x848, 0x1000); - outl(0x844, 0x1000); + outl(0x844, 0x1000); /* ack it */ } } if (inl(0x834) & 0x4000) dolog("Long periodic timer"); if (inl(0x840) & 0x1000) { - dolog("Caught device monitor trap"); pci_dump(); outl(0x840, 0x1100); outl(0x840, 0x0100); diff --git a/aseg/firstrun.c b/aseg/firstrun.c index ace70c6..9977d14 100644 --- a/aseg/firstrun.c +++ b/aseg/firstrun.c @@ -1,4 +1,5 @@ #include +#include void __firstrun_start() { /* @@ -22,6 +23,7 @@ void __firstrun_start() { pci_write16(0, 31, 4, 0xC0, 0); /* Turn on the SMIs we want */ - outb(0x830, inb(0x830) | 0x41); + outb(0x830, inb(0x830) | 0x40); + smi_enable(); } diff --git a/grubload/Makefile b/grubload/Makefile index 4eef921..bc4c1fe 100644 --- a/grubload/Makefile +++ b/grubload/Makefile @@ -1,4 +1,4 @@ -OBJS=multiboot_c.o multiboot_asm.o realmode.o loader.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o ../ich2/smram-ich2.o +OBJS=multiboot_c.o multiboot_asm.o realmode.o loader.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o ../ich2/smram-ich2.o ../ich2/smi.o CC=gcc CFLAGS=-nostdlib -I../include -I../include/raw -I. -D__RAW__ -fno-builtin -nostdinc diff --git a/grubload/multiboot_c.c b/grubload/multiboot_c.c index 6fcfa5e..e4843c3 100644 --- a/grubload/multiboot_c.c +++ b/grubload/multiboot_c.c @@ -1,7 +1,9 @@ #include "console.h" +#include #include #include #include +#include #define INFO_SIGNATURE 0x5754454E @@ -54,7 +56,7 @@ void c_start(unsigned int magic, struct mb_info *mbinfo) puts("Current SMI state is: "); puthex(inl(0x830)); puts("\n"); puts("Current SMRAMC state is: "); puthex(pci_read8(0, 0, 0, 0x70)); puts("\n"); - outl(0x830, inl(0x830) & ~0x1); /* turn off SMIs */ + smi_disable(); /* Try really hard to shut up USB_LEGKEY. */ pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0)); @@ -62,7 +64,6 @@ void c_start(unsigned int magic, struct mb_info *mbinfo) pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0)); pci_write16(0, 31, 4, 0xC0, 0); - /* Open the SMRAM aperture and load our ELF. */ smram_state_t old_smramc = smram_save_state(); diff --git a/ich2/smi.c b/ich2/smi.c new file mode 100644 index 0000000..59f14b6 --- /dev/null +++ b/ich2/smi.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +uint16_t _get_PMBASE() +{ + return pci_read32(0, 0, 0, 0x40) & 0xFF80; +} + +void smi_disable() +{ + unsigned short smi_en = _get_PMBASE() + 0x30; + outl(smi_en, inl(smi_en) & ~0x0001); +} + +void smi_enable() +{ + unsigned short smi_en = _get_PMBASE() + 0x30; + outl(smi_en, inl(smi_en) | 0x0001); +} + +unsigned long smi_status() +{ + unsigned short smi_sts = _get_PMBASE() + 0x34; + return inl(smi_sts); +} diff --git a/include/smi.h b/include/smi.h new file mode 100644 index 0000000..c669fc2 --- /dev/null +++ b/include/smi.h @@ -0,0 +1,10 @@ +#ifndef SMI_H +#define SMI_H + +extern void smi_disable(); /* akin to cli / sti */ +extern void smi_enable(); + +extern void smi_poll(); +extern unsigned long smi_status(); /* Architecturally defined; for debugging only. */ + +#endif