wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 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 | |
wdenk | 591dda5 | 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 | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 34 | #include <pci.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 35 | #include <asm/realmode.h> |
| 36 | #include <asm/io.h> |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 37 | #include "bios.h" |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 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 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 43 | static int set_jmp_vector(int entry_point, void *target) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 44 | { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 45 | if (entry_point & ~0xffff) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 46 | return -1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 47 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 48 | if (((u32)target - 0xf0000) & ~0xffff) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 49 | return -1; |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 50 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 51 | printf("set_jmp_vector: 0xf000:%04x -> %p\n", |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 52 | entry_point, target); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 53 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 54 | /* jmp opcode */ |
| 55 | writeb(0xea, 0xf0000 + entry_point); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 56 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 57 | /* offset */ |
| 58 | writew(((u32)target-0xf0000), 0xf0000 + entry_point + 1); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 59 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 60 | /* segment */ |
| 61 | writew(0xf000, 0xf0000 + entry_point + 3); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 62 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 66 | /* Install an interrupt vector */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 67 | static void setvector(int vector, u16 segment, void *handler) |
| 68 | { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 69 | u16 *ptr = (u16 *)(vector * 4); |
| 70 | ptr[0] = ((u32)handler - (segment << 4)) & 0xffff; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 71 | ptr[1] = segment; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 72 | |
| 73 | #if 0 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 74 | printf("setvector: int%02x -> %04x:%04x\n", |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 75 | vector, ptr[1], ptr[0]); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 76 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | int bios_setup(void) |
| 80 | { |
Graeme Russ | ae428db | 2010-10-07 20:03:31 +1100 | [diff] [blame] | 81 | ulong bios_start = (ulong)&__bios_start + gd->reloc_off; |
| 82 | ulong bios_size = (ulong)&__bios_size; |
Graeme Russ | 759cbb2 | 2009-11-24 20:04:20 +1100 | [diff] [blame] | 83 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 84 | static int done; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 85 | int vector; |
Graeme Russ | 2fe2a97 | 2008-09-07 07:08:42 +1000 | [diff] [blame] | 86 | #ifdef CONFIG_PCI |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 87 | struct pci_controller *pri_hose; |
Graeme Russ | 2fe2a97 | 2008-09-07 07:08:42 +1000 | [diff] [blame] | 88 | #endif |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 89 | if (done) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 90 | return 0; |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 91 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 92 | done = 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 93 | |
Graeme Russ | ae428db | 2010-10-07 20:03:31 +1100 | [diff] [blame] | 94 | if (bios_size > 65536) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 95 | printf("BIOS too large (%ld bytes, max is 65536)\n", |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 96 | bios_size); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 97 | return -1; |
| 98 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 99 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 100 | memcpy(BIOS_BASE, (void *)bios_start, bios_size); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 101 | |
| 102 | /* clear bda */ |
| 103 | memset(BIOS_DATA, 0, BIOS_DATA_SIZE); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 104 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 105 | /* enter some values to the bda */ |
| 106 | writew(0x3f8, BIOS_DATA); /* com1 addr */ |
| 107 | writew(0x2f8, BIOS_DATA+2); /* com2 addr */ |
| 108 | writew(0x3e8, BIOS_DATA+4); /* com3 addr */ |
| 109 | writew(0x2e8, BIOS_DATA+6); /* com4 addr */ |
| 110 | writew(0x278, BIOS_DATA+8); /* lpt1 addr */ |
| 111 | /* |
| 112 | * The kernel wants to read the base memory size |
| 113 | * from 40:13. Put a zero there to avoid an error message |
| 114 | */ |
| 115 | writew(0, BIOS_DATA+0x13); /* base memory size */ |
| 116 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 117 | |
| 118 | /* setup realmode interrupt vectors */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame^] | 119 | for (vector = 0; vector < NUMVECTS; vector++) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 120 | setvector(vector, BIOS_CS, &rm_def_int); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 121 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 122 | setvector(0x00, BIOS_CS, &rm_int00); |
| 123 | setvector(0x01, BIOS_CS, &rm_int01); |
| 124 | setvector(0x02, BIOS_CS, &rm_int02); |
| 125 | setvector(0x03, BIOS_CS, &rm_int03); |
| 126 | setvector(0x04, BIOS_CS, &rm_int04); |
| 127 | setvector(0x05, BIOS_CS, &rm_int05); |
| 128 | setvector(0x06, BIOS_CS, &rm_int06); |
| 129 | setvector(0x07, BIOS_CS, &rm_int07); |
| 130 | setvector(0x08, BIOS_CS, &rm_int08); |
| 131 | setvector(0x09, BIOS_CS, &rm_int09); |
| 132 | setvector(0x0a, BIOS_CS, &rm_int0a); |
| 133 | setvector(0x0b, BIOS_CS, &rm_int0b); |
| 134 | setvector(0x0c, BIOS_CS, &rm_int0c); |
| 135 | setvector(0x0d, BIOS_CS, &rm_int0d); |
| 136 | setvector(0x0e, BIOS_CS, &rm_int0e); |
| 137 | setvector(0x0f, BIOS_CS, &rm_int0f); |
| 138 | setvector(0x10, BIOS_CS, &rm_int10); |
| 139 | setvector(0x11, BIOS_CS, &rm_int11); |
| 140 | setvector(0x12, BIOS_CS, &rm_int12); |
| 141 | setvector(0x13, BIOS_CS, &rm_int13); |
| 142 | setvector(0x14, BIOS_CS, &rm_int14); |
| 143 | setvector(0x15, BIOS_CS, &rm_int15); |
| 144 | setvector(0x16, BIOS_CS, &rm_int16); |
| 145 | setvector(0x17, BIOS_CS, &rm_int17); |
| 146 | setvector(0x18, BIOS_CS, &rm_int18); |
| 147 | setvector(0x19, BIOS_CS, &rm_int19); |
| 148 | setvector(0x1a, BIOS_CS, &rm_int1a); |
| 149 | setvector(0x1b, BIOS_CS, &rm_int1b); |
| 150 | setvector(0x1c, BIOS_CS, &rm_int1c); |
| 151 | setvector(0x1d, BIOS_CS, &rm_int1d); |
| 152 | setvector(0x1e, BIOS_CS, &rm_int1e); |
| 153 | setvector(0x1f, BIOS_CS, &rm_int1f); |
| 154 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 155 | set_jmp_vector(0xfff0, &realmode_reset); |
| 156 | set_jmp_vector(0xfe6e, &realmode_pci_bios_call_entry); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 157 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 158 | /* fill in data area */ |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 159 | RELOC_16_WORD(0xf000, ram_in_64kb_chunks) = gd->ram_size >> 16; |
| 160 | RELOC_16_WORD(0xf000, bios_equipment) = 0; /* FixMe */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 161 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 162 | /* If we assume only one PCI hose, this PCI hose |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 163 | * will own PCI bus #0, and the last PCI bus of |
| 164 | * that PCI hose will be the last PCI bus in the |
| 165 | * system. |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 166 | * (This, ofcause break on multi hose systems, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 167 | * but our PCI BIOS only support one hose anyway) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 168 | */ |
Graeme Russ | 2fe2a97 | 2008-09-07 07:08:42 +1000 | [diff] [blame] | 169 | #ifdef CONFIG_PCI |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 170 | pri_hose = pci_bus_to_hose(0); |
| 171 | if (NULL != pri_hose) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 172 | /* fill in last pci bus number for use by the realmode |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 173 | * PCI BIOS */ |
| 174 | RELOC_16_BYTE(0xf000, pci_last_bus) = pri_hose->last_busno; |
| 175 | } |
Graeme Russ | 2fe2a97 | 2008-09-07 07:08:42 +1000 | [diff] [blame] | 176 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 177 | return 0; |
| 178 | } |