]>
Commit | Line | Data |
---|---|---|
3c4e084d JP |
1 | /* smi.c |
2 | * First-run SMI C entry point | |
3 | * NetWatch system management mode administration console | |
4 | * | |
5 | * Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved. | |
6 | * This program is free software; you can redistribute and/or modify it under | |
7 | * the terms found in the file LICENSE in the root of this source tree. | |
8 | * | |
9 | */ | |
10 | ||
9e2a82e4 JP |
11 | #include <io.h> |
12 | #include <smram.h> | |
13 | #include <video_defines.h> | |
14 | #include <minilib.h> | |
15 | #include <smi.h> | |
16 | #include <pci-bother.h> | |
113df320 | 17 | #include <serial.h> |
c77a83d6 JW |
18 | #include <fb.h> |
19 | #include <output.h> | |
eda689ee | 20 | #include <msr.h> |
9e2a82e4 JP |
21 | #include "../net/net.h" |
22 | #include "vga-overlay.h" | |
23 | ||
9e2a82e4 | 24 | unsigned int counter = 0; |
9e2a82e4 JP |
25 | unsigned long pcisave = 0; |
26 | unsigned char vgasave = 0; | |
27 | ||
9e2a82e4 JP |
28 | void smi_entry(void) |
29 | { | |
30 | char statstr[512]; | |
68beefa8 | 31 | |
eda689ee JW |
32 | /* Reenable caching on SMRAM. */ |
33 | WRMSR(0x202, (RDMSR(0x202) & ~(0xFFULL)) | 0x06ULL); | |
34 | ||
9e2a82e4 JP |
35 | pcisave = inl(0xCF8); |
36 | vgasave = inb(0x3D4); | |
9e2a82e4 | 37 | pci_unbother_all(); |
c77a83d6 JW |
38 | |
39 | serial_init(); | |
40 | ||
41 | if (fb) | |
42 | fb->getvmode(fb->priv); | |
68beefa8 | 43 | |
9e2a82e4 | 44 | counter++; |
5cb80fe1 JW |
45 | if (!fb || fb->curmode.text) |
46 | { | |
47 | sprintf(statstr, "NetWatch! %08x %08x", smi_status(), counter); | |
48 | strblit(statstr, 0, 0, 0); | |
49 | } | |
9e2a82e4 | 50 | |
9e2a82e4 | 51 | eth_poll(); |
9e2a82e4 JP |
52 | |
53 | if (inl(0x840) & 0x1000) | |
54 | { | |
55 | /* | |
56 | pci_dump(); | |
57 | */ | |
58 | outl(0x840, 0x1100); | |
59 | outl(0x840, 0x0100); | |
60 | } | |
61 | ||
113df320 | 62 | |
9e2a82e4 | 63 | smi_poll(); |
68beefa8 | 64 | |
9e2a82e4 | 65 | pci_bother_all(); |
9e2a82e4 JP |
66 | outl(0xCF8, pcisave); |
67 | outb(0x3D4, vgasave); | |
eda689ee JW |
68 | |
69 | /* Disable caching on SMRAM again, to prevent the user from whacking us. */ | |
70 | WRMSR(0x202, RDMSR(0x202) & ~(0xFFULL)); | |
9e2a82e4 JP |
71 | } |
72 | ||
722e5aea JP |
73 | extern void timer_handler(smi_event_t ev); |
74 | extern void kbc_handler(smi_event_t ev); | |
75 | extern void gbl_rls_handler(smi_event_t ev); | |
6093edb5 | 76 | extern void cs410_pwrbtn_handler(smi_event_t ev); |
9e2a82e4 | 77 | |
722e5aea | 78 | void __firstrun_stub() { |
9e2a82e4 | 79 | |
722e5aea JP |
80 | /* Try really hard to shut up USB_LEGKEY. */ |
81 | pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0)); | |
82 | pci_write16(0, 31, 2, 0xC0, 0); | |
83 | pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0)); | |
84 | pci_write16(0, 31, 4, 0xC0, 0); | |
9e2a82e4 | 85 | |
722e5aea JP |
86 | /* Turn on the SMIs we want */ |
87 | smi_disable(); | |
9e2a82e4 JP |
88 | |
89 | smi_register_handler(SMI_EVENT_FAST_TIMER, timer_handler); | |
90 | smi_enable_event(SMI_EVENT_FAST_TIMER); | |
91 | ||
722e5aea JP |
92 | smi_register_handler(SMI_EVENT_DEVTRAP_KBC, kbc_handler); |
93 | smi_enable_event(SMI_EVENT_DEVTRAP_KBC); | |
94 | ||
95 | smi_register_handler(SMI_EVENT_GBL_RLS, gbl_rls_handler); | |
96 | smi_enable_event(SMI_EVENT_GBL_RLS); | |
6093edb5 JW |
97 | |
98 | smi_register_handler(SMI_EVENT_PWRBTN, cs410_pwrbtn_handler); | |
99 | smi_enable_event(SMI_EVENT_PWRBTN); | |
722e5aea | 100 | |
9e2a82e4 JP |
101 | smi_enable(); |
102 | } |