--- /dev/null
+smm-open-ich2:
+ gcc -o smm-open-ich2 smm-open-ich2.c ../pci/pci-linux.c
--- /dev/null
+#ifndef _REG_82815_H
+#define _REG_82815_H
+
+#define DRP 0x52
+#define DRP2 0x54
+
+#define SMRAMC 0x70
+#define SMRAMC_LOCK 0x02
+#define SMRAMC_LSMM 0x0C
+#define SMRAMC_USMM 0x30
+#define SMRAMC_GMS 0xC0
+
+#endif
--- /dev/null
+#include "reg-82815.h"
+
+unsigned long memsz[] = {
+ 0, // 0
+ 32*1024*1024, // 1
+ 32*1024*1024, // 2
+ 48*1024*1024, // 3
+ 64*1024*1024, // 4
+ 64*1024*1024, // 5
+ 96*1024*1024, // 6
+ 128*1024*1024, // 7
+ 128*1024*1024, // 8
+ 128*1024*1024, // 9
+ 128*1024*1024, // A
+ 192*1024*1024, // B
+ 256*1024*1024, // C
+ 256*1024*1024, // D
+ 256*1024*1024, // E
+ 512*1024*1024 // F
+};
+
+int main()
+{
+ unsigned char smramc, drp, drp2;
+ unsigned int tom = 0;
+ int usmm, lsmm;
+
+ smramc = pci_read8(0, 0, 0, SMRAMC);
+ drp = pci_read8(0, 0, 0, DRP);
+ drp2 = pci_read8(0, 0, 0, DRP2);
+
+ tom += memsz[drp & 0xF];
+ tom += memsz[drp >> 4];
+ tom += memsz[drp2 & 0xF];
+
+ printf("Top of DRAM: %08x\n", tom);
+
+ printf("SMRAMC: %02x\n", smramc);
+ if (smramc & SMRAMC_LOCK)
+ {
+ printf("SMRAM is locked, cannot load anything :-(\n");
+ return 1;
+ }
+
+ usmm = (smramc >> 4) & 0x3;
+ lsmm = (smramc >> 2) & 0x3;
+
+ switch (usmm)
+ {
+ case 0:
+ printf("TSEG and HSEG both off\n");
+ break;
+ case 1:
+ printf("TSEG off, HSEG %s\n", lsmm ? "off" : "on");
+ break;
+ case 2:
+ printf("TSEG 512KB (%08x - %08x), HSEG %s\n", tom - 512 * 1024, tom - 1, lsmm ? "off" : "on");
+ break;
+ case 3:
+ printf("TSEG 1MB (%08x - %08x), HSEG %s\n", tom - 1 * 1024 * 1024, tom - 1, lsmm ? "off" : "on");
+ break;
+ }
+
+ switch (lsmm)
+ {
+ case 0:
+ printf("ABSEG disabled\n");
+ break;
+ case 1:
+ printf("ABSEG enabled as system RAM\n");
+ break;
+ case 2:
+ printf("ABSEG enabled for SMM code only\n");
+ break;
+ case 3:
+ printf("ABSEG enabled for both SMM code and data\n");
+ break;
+ }
+ return 0;
+}
--- /dev/null
+#ifndef _REG_82865_H
+#define _REG_82865_H
+
+#define SMRAMC 0x9D
+#define SMRAMC_ENABLE 0x8
+#define SMRAMC_LOCK 0x10
+#define SMRAMC_CLOSE 0x20
+#define SMRAMC_OPEN 0x40
+#define ESMRAMC 0x9E
+#define ESMRAMC_TSEGEN 0x1
+#define ESMRAMC_TSEGSZ 0x6
+#define ESMRAMC_SMERR 0x40
+#define ESMRAMC_HISMRAM 0x80
+
+
+#endif
--- /dev/null
+#include "reg-82865.h"
+
+void main()
+{
+ unsigned char smramc, esmramc;
+ unsigned int toud;
+
+ smramc = pci_read8(0, 0, 0, SMRAMC);
+ esmramc = pci_read8(0, 0, 0, ESMRAMC);
+
+ toud = (pci_read16(0, 0, 0, 0xC4) >> 3) << 19;
+ printf("Usable DRAM: %d bytes\n", toud);
+
+ printf("SMRAMC: %02x\n", smramc);
+ printf("ESMRAMC: %02x\n", smramc);
+ if (smramc & SMRAMC_LOCK)
+ {
+ printf("SMRAM is locked, cannot load anything :-(\n");
+ return;
+ }
+}
\ No newline at end of file
--- /dev/null
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <inttypes.h>
+
+static int _open(int bus, int slot, int fn)
+{
+ char fname[512];
+
+ sprintf(fname, "/proc/bus/pci/%02x/%02x.%01x", bus, slot, fn);
+ return open(fname, O_RDWR);
+}
+
+void pci_write32(int bus, int slot, int fn, int addr, uint32_t data)
+{
+ int fd;
+
+ fd = _open(bus, slot, fn);
+ if (fd < 0)
+ return;
+ lseek(fd, addr, SEEK_SET);
+ write(fd, &data, 4);
+ close(fd);
+}
+
+void pci_write16(int bus, int slot, int fn, int addr, uint16_t data)
+{
+ int fd;
+
+ fd = _open(bus, slot, fn);
+ if (fd < 0)
+ return;
+ lseek(fd, addr, SEEK_SET);
+ write(fd, &data, 2);
+ close(fd);
+}
+
+void pci_write8(int bus, int slot, int fn, int addr, uint8_t data)
+{
+ int fd;
+
+ fd = _open(bus, slot, fn);
+ if (fd < 0)
+ return;
+ lseek(fd, addr, SEEK_SET);
+ write(fd, &data, 1);
+ close(fd);
+}
+
+uint32_t pci_read32(int bus, int slot, int fn, int addr)
+{
+ int fd;
+ uint32_t data;
+
+ fd = _open(bus, slot, fn);
+ if (fd < 0)
+ return;
+ lseek(fd, addr, SEEK_SET);
+ read(fd, &data, 4);
+ close(fd);
+
+ return data;
+}
+
+uint16_t pci_read16(int bus, int slot, int fn, int addr)
+{
+ int fd;
+ uint16_t data;
+
+ fd = _open(bus, slot, fn);
+ if (fd < 0)
+ {
+ perror("open");
+ return;
+ }
+ lseek(fd, addr, SEEK_SET);
+ read(fd, &data, 2);
+ close(fd);
+
+ return data;
+}
+
+
+uint8_t pci_read8(int bus, int slot, int fn, int addr)
+{
+ int fd;
+ uint8_t data;
+
+ fd = _open(bus, slot, fn);
+ if (fd < 0)
+ {
+ perror("open");
+ return;
+ }
+ lseek(fd, addr, SEEK_SET);
+ read(fd, &data, 1);
+ close(fd);
+
+ return data;
+}