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