blob: f45ef31e0725bf52666d82d665a461e83dce9163 [file] [log] [blame]
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +00001/*
2 * acpi_reset.c: Reboot your LinuxBIOS system with ACPI software watchdo
3 *
4 *
5 * Copyright 2000 Silicon Integrated System Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 *
22 * Reference:
23 * 1. SiS 630 Specification
24 *
25 * $Id$
26 */
27
28#include <errno.h>
29#include <fcntl.h>
30#include <sys/mman.h>
31#include <sys/io.h>
32#include <unistd.h>
33#include <stdio.h>
34
35unsigned short acpi_base;
36
37void
38waitsmbus()
39{
40 unsigned short port = acpi_base;
41 unsigned char val;
42
43 //printf("waitsmb ..\n");
44
45 for (val = inb(port); (val & 8) == 0; val = inb(port))
46 ;
47 //printf("past first test\n");
48}
49
50void
51setsmbus(unsigned char index, unsigned char value)
52{
53 unsigned short port = acpi_base + index;
54
55 //printf("setsmbus: index 0x%02x, value 0x%02x\n",
56 // index, value);
57
58 outb(value, port);
59}
60
61unsigned char
62getsmbus(unsigned char index)
63{
64 unsigned short port = acpi_base + index;
65 unsigned char value;
66
67 value = inb(port);
68
69 //printf("getsmbus: index 0x%02x, value 0x%02x\n",
70 // index, value);
71
72 return value;
73}
74
75unsigned char
76read_spd(unsigned char slot, unsigned char index)
77{
78 unsigned char value;
79
80 setsmbus(0x03, 0x20);
81
82 setsmbus(0x04, 0xA1 + (slot << 1));
83
84 setsmbus(0x05, index);
85
86 setsmbus(0x03, 0x12);
87
88 waitsmbus();
89
90 value = getsmbus(0x08);
91
92 setsmbus(0x00, 0xFF);
93
94 return value;
95}
96
97main()
98{
99 unsigned char b;
100 unsigned short w;
101
102
103 /* get io privilege access PCI configuration space */
104 if (iopl(3) != 0) {
105 perror("Can not set io priviliage");
106 exit(1);
107 }
108
109 /* Enable ACPI by set B7 on Reg 0x40, LPC */
110 outl(0x80000840, 0x0cf8);
111 b = inb(0x0cfc) | 0x80;
112 outb(b, 0xcfc);
113
114 /* get the ACPI base address for register 0x74,0x75 of LPC */
115 outl(0x80000874, 0x0cf8);
116 w = inw(0x0cfc);
117 acpi_base = w + 0x80;
118
119 printf("Number of bytes used by module manufacturer 0x%02x\n",
120 read_spd(0x00, 0x00));
121
122 printf("Memory Type 0x%02x\n",
123 read_spd(0x00, 0x02));
124
125 printf("Number of Row Address bits 0x%02x\n",
126 read_spd(0x00, 0x03));
127
128 printf("Number of Column Address bits 0x%02x\n",
129 read_spd(0x00, 0x04));
130
131 printf("Number of Sides 0x%02x\n",
132 read_spd(0x00, 0x05));
133
134 printf("Number of Banks 0x%02x\n",
135 read_spd(0x00, 0x11));
136}