wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Daniel Engström, Omicron Ceti AB, daniel@omicron.se |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 4 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | /* |
| 26 | * Partly based on msbios.c from rolo 1.6: |
| 27 | *---------------------------------------------------------------------- |
| 28 | * (C) Copyright 2000 |
| 29 | * Sysgo Real-Time Solutions GmbH |
| 30 | * Klein-Winternheim, Germany |
| 31 | *---------------------------------------------------------------------- |
| 32 | */ |
| 33 | |
| 34 | #include <common.h> |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 35 | #include <pci.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 36 | #include <asm/realmode.h> |
| 37 | #include <asm/io.h> |
| 38 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 41 | #define NUMVECTS 256 |
| 42 | |
| 43 | #define BIOS_DATA ((char*)0x400) |
| 44 | #define BIOS_DATA_SIZE 256 |
| 45 | #define BIOS_BASE ((char*)0xf0000) |
| 46 | #define BIOS_CS 0xf000 |
| 47 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 48 | /* these are defined in a 16bit segment and needs |
| 49 | * to be accessed with the RELOC_16_xxxx() macros below |
| 50 | */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 51 | extern u16 ram_in_64kb_chunks; |
| 52 | extern u16 bios_equipment; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 53 | extern u8 pci_last_bus; |
| 54 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 55 | extern void *rm_int00; |
| 56 | extern void *rm_int01; |
| 57 | extern void *rm_int02; |
| 58 | extern void *rm_int03; |
| 59 | extern void *rm_int04; |
| 60 | extern void *rm_int05; |
| 61 | extern void *rm_int06; |
| 62 | extern void *rm_int07; |
| 63 | extern void *rm_int08; |
| 64 | extern void *rm_int09; |
| 65 | extern void *rm_int0a; |
| 66 | extern void *rm_int0b; |
| 67 | extern void *rm_int0c; |
| 68 | extern void *rm_int0d; |
| 69 | extern void *rm_int0e; |
| 70 | extern void *rm_int0f; |
| 71 | extern void *rm_int10; |
| 72 | extern void *rm_int11; |
| 73 | extern void *rm_int12; |
| 74 | extern void *rm_int13; |
| 75 | extern void *rm_int14; |
| 76 | extern void *rm_int15; |
| 77 | extern void *rm_int16; |
| 78 | extern void *rm_int17; |
| 79 | extern void *rm_int18; |
| 80 | extern void *rm_int19; |
| 81 | extern void *rm_int1a; |
| 82 | extern void *rm_int1b; |
| 83 | extern void *rm_int1c; |
| 84 | extern void *rm_int1d; |
| 85 | extern void *rm_int1e; |
| 86 | extern void *rm_int1f; |
| 87 | extern void *rm_def_int; |
| 88 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 89 | extern void *realmode_reset; |
| 90 | extern void *realmode_pci_bios_call_entry; |
| 91 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 92 | static int set_jmp_vector(int entry_point, void *target) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 93 | { |
| 94 | if (entry_point & ~0xffff) { |
| 95 | return -1; |
| 96 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 97 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 98 | if (((u32)target-0xf0000) & ~0xffff) { |
| 99 | return -1; |
| 100 | } |
| 101 | printf("set_jmp_vector: 0xf000:%04x -> %p\n", |
| 102 | entry_point, target); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 103 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 104 | /* jmp opcode */ |
| 105 | writeb(0xea, 0xf0000 + entry_point); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 106 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 107 | /* offset */ |
| 108 | writew(((u32)target-0xf0000), 0xf0000 + entry_point + 1); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 109 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 110 | /* segment */ |
| 111 | writew(0xf000, 0xf0000 + entry_point + 3); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 112 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 117 | /* |
| 118 | ************************************************************ |
| 119 | * Install an interrupt vector |
| 120 | ************************************************************ |
| 121 | */ |
| 122 | |
| 123 | static void setvector(int vector, u16 segment, void *handler) |
| 124 | { |
| 125 | u16 *ptr = (u16*)(vector*4); |
| 126 | ptr[0] = ((u32)handler - (segment << 4))&0xffff; |
| 127 | ptr[1] = segment; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 128 | |
| 129 | #if 0 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 130 | printf("setvector: int%02x -> %04x:%04x\n", |
| 131 | vector, ptr[1], ptr[0]); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 132 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 133 | } |
| 134 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | #define RELOC_16_LONG(seg, off) *(u32*)(seg << 4 | (u32)&off) |
| 136 | #define RELOC_16_WORD(seg, off) *(u16*)(seg << 4 | (u32)&off) |
| 137 | #define RELOC_16_BYTE(seg, off) *(u8*)(seg << 4 | (u32)&off) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 138 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 139 | int bios_setup(void) |
| 140 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 141 | static int done=0; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 142 | int vector; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 143 | struct pci_controller *pri_hose; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 144 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 145 | if (done) { |
| 146 | return 0; |
| 147 | } |
| 148 | done = 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 149 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 150 | if (i386boot_bios_size > 65536) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 151 | printf("BIOS too large (%ld bytes, max is 65536)\n", |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 152 | i386boot_bios_size); |
| 153 | return -1; |
| 154 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 155 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 156 | memcpy(BIOS_BASE, (void*)i386boot_bios, i386boot_bios_size); |
| 157 | |
| 158 | /* clear bda */ |
| 159 | memset(BIOS_DATA, 0, BIOS_DATA_SIZE); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 160 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 161 | /* enter some values to the bda */ |
| 162 | writew(0x3f8, BIOS_DATA); /* com1 addr */ |
| 163 | writew(0x2f8, BIOS_DATA+2); /* com2 addr */ |
| 164 | writew(0x3e8, BIOS_DATA+4); /* com3 addr */ |
| 165 | writew(0x2e8, BIOS_DATA+6); /* com4 addr */ |
| 166 | writew(0x278, BIOS_DATA+8); /* lpt1 addr */ |
| 167 | /* |
| 168 | * The kernel wants to read the base memory size |
| 169 | * from 40:13. Put a zero there to avoid an error message |
| 170 | */ |
| 171 | writew(0, BIOS_DATA+0x13); /* base memory size */ |
| 172 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 173 | |
| 174 | /* setup realmode interrupt vectors */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 175 | for (vector = 0; vector < NUMVECTS; vector++) { |
| 176 | setvector(vector, BIOS_CS, &rm_def_int); |
| 177 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 178 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 179 | setvector(0x00, BIOS_CS, &rm_int00); |
| 180 | setvector(0x01, BIOS_CS, &rm_int01); |
| 181 | setvector(0x02, BIOS_CS, &rm_int02); |
| 182 | setvector(0x03, BIOS_CS, &rm_int03); |
| 183 | setvector(0x04, BIOS_CS, &rm_int04); |
| 184 | setvector(0x05, BIOS_CS, &rm_int05); |
| 185 | setvector(0x06, BIOS_CS, &rm_int06); |
| 186 | setvector(0x07, BIOS_CS, &rm_int07); |
| 187 | setvector(0x08, BIOS_CS, &rm_int08); |
| 188 | setvector(0x09, BIOS_CS, &rm_int09); |
| 189 | setvector(0x0a, BIOS_CS, &rm_int0a); |
| 190 | setvector(0x0b, BIOS_CS, &rm_int0b); |
| 191 | setvector(0x0c, BIOS_CS, &rm_int0c); |
| 192 | setvector(0x0d, BIOS_CS, &rm_int0d); |
| 193 | setvector(0x0e, BIOS_CS, &rm_int0e); |
| 194 | setvector(0x0f, BIOS_CS, &rm_int0f); |
| 195 | setvector(0x10, BIOS_CS, &rm_int10); |
| 196 | setvector(0x11, BIOS_CS, &rm_int11); |
| 197 | setvector(0x12, BIOS_CS, &rm_int12); |
| 198 | setvector(0x13, BIOS_CS, &rm_int13); |
| 199 | setvector(0x14, BIOS_CS, &rm_int14); |
| 200 | setvector(0x15, BIOS_CS, &rm_int15); |
| 201 | setvector(0x16, BIOS_CS, &rm_int16); |
| 202 | setvector(0x17, BIOS_CS, &rm_int17); |
| 203 | setvector(0x18, BIOS_CS, &rm_int18); |
| 204 | setvector(0x19, BIOS_CS, &rm_int19); |
| 205 | setvector(0x1a, BIOS_CS, &rm_int1a); |
| 206 | setvector(0x1b, BIOS_CS, &rm_int1b); |
| 207 | setvector(0x1c, BIOS_CS, &rm_int1c); |
| 208 | setvector(0x1d, BIOS_CS, &rm_int1d); |
| 209 | setvector(0x1e, BIOS_CS, &rm_int1e); |
| 210 | setvector(0x1f, BIOS_CS, &rm_int1f); |
| 211 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 212 | set_jmp_vector(0xfff0, &realmode_reset); |
| 213 | set_jmp_vector(0xfe6e, &realmode_pci_bios_call_entry); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 214 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 215 | /* fill in data area */ |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 216 | RELOC_16_WORD(0xf000, ram_in_64kb_chunks) = gd->ram_size >> 16; |
| 217 | RELOC_16_WORD(0xf000, bios_equipment) = 0; /* FixMe */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 218 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 219 | /* If we assume only one PCI hose, this PCI hose |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 220 | * will own PCI bus #0, and the last PCI bus of |
| 221 | * that PCI hose will be the last PCI bus in the |
| 222 | * system. |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 223 | * (This, ofcause break on multi hose systems, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 224 | * but our PCI BIOS only support one hose anyway) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 225 | */ |
| 226 | pri_hose = pci_bus_to_hose(0); |
| 227 | if (NULL != pri_hose) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 228 | /* fill in last pci bus number for use by the realmode |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 229 | * PCI BIOS */ |
| 230 | RELOC_16_BYTE(0xf000, pci_last_bus) = pri_hose->last_busno; |
| 231 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 232 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 233 | return 0; |
| 234 | } |