blob: 265f7d671ee3dce8efb8f09004b25466dfca0c7d [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
2 * (C) Copyright 2002
Albert ARIBAUDfa82f872011-08-04 18:45:45 +02003 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk8bde7f72003-06-27 21:31:46 +00004 *
wdenk2262cfe2002-11-18 00:14:45 +00005 * 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
wdenk2262cfe2002-11-18 00:14:45 +000024/*
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>
wdenk7a8e9bed2003-05-31 18:35:21 +000034#include <pci.h>
wdenk2262cfe2002-11-18 00:14:45 +000035#include <asm/realmode.h>
36#include <asm/io.h>
Graeme Russ83088af2011-11-08 02:33:15 +000037#include "bios.h"
wdenk2262cfe2002-11-18 00:14:45 +000038
Wolfgang Denkd87080b2006-03-31 18:32:53 +020039DECLARE_GLOBAL_DATA_PTR;
40
wdenk2262cfe2002-11-18 00:14:45 +000041#define NUMVECTS 256
42
wdenk8bde7f72003-06-27 21:31:46 +000043static int set_jmp_vector(int entry_point, void *target)
wdenk7a8e9bed2003-05-31 18:35:21 +000044{
Graeme Russ83088af2011-11-08 02:33:15 +000045 if (entry_point & ~0xffff)
wdenk7a8e9bed2003-05-31 18:35:21 +000046 return -1;
wdenk8bde7f72003-06-27 21:31:46 +000047
Graeme Russ83088af2011-11-08 02:33:15 +000048 if (((u32)target - 0xf0000) & ~0xffff)
wdenk7a8e9bed2003-05-31 18:35:21 +000049 return -1;
Graeme Russ83088af2011-11-08 02:33:15 +000050
wdenk7a8e9bed2003-05-31 18:35:21 +000051 printf("set_jmp_vector: 0xf000:%04x -> %p\n",
Graeme Russ83088af2011-11-08 02:33:15 +000052 entry_point, target);
wdenk8bde7f72003-06-27 21:31:46 +000053
wdenk7a8e9bed2003-05-31 18:35:21 +000054 /* jmp opcode */
55 writeb(0xea, 0xf0000 + entry_point);
wdenk8bde7f72003-06-27 21:31:46 +000056
wdenk7a8e9bed2003-05-31 18:35:21 +000057 /* offset */
58 writew(((u32)target-0xf0000), 0xf0000 + entry_point + 1);
wdenk8bde7f72003-06-27 21:31:46 +000059
wdenk7a8e9bed2003-05-31 18:35:21 +000060 /* segment */
61 writew(0xf000, 0xf0000 + entry_point + 3);
wdenk8bde7f72003-06-27 21:31:46 +000062
wdenk7a8e9bed2003-05-31 18:35:21 +000063 return 0;
64}
65
Graeme Russ83088af2011-11-08 02:33:15 +000066/* Install an interrupt vector */
wdenk2262cfe2002-11-18 00:14:45 +000067static void setvector(int vector, u16 segment, void *handler)
68{
Graeme Russ83088af2011-11-08 02:33:15 +000069 u16 *ptr = (u16 *)(vector * 4);
70 ptr[0] = ((u32)handler - (segment << 4)) & 0xffff;
wdenk2262cfe2002-11-18 00:14:45 +000071 ptr[1] = segment;
wdenk8bde7f72003-06-27 21:31:46 +000072
73#if 0
wdenk2262cfe2002-11-18 00:14:45 +000074 printf("setvector: int%02x -> %04x:%04x\n",
Graeme Russ83088af2011-11-08 02:33:15 +000075 vector, ptr[1], ptr[0]);
wdenk8bde7f72003-06-27 21:31:46 +000076#endif
wdenk2262cfe2002-11-18 00:14:45 +000077}
78
79int bios_setup(void)
80{
Gabe Black769db032011-11-12 16:34:48 +000081 /* The BIOS section is not relocated and still in the ROM. */
82 ulong bios_start = (ulong)&__bios_start;
Graeme Russ067f9b12010-10-07 20:03:31 +110083 ulong bios_size = (ulong)&__bios_size;
Graeme Russcabe5792009-11-24 20:04:20 +110084
Graeme Russ83088af2011-11-08 02:33:15 +000085 static int done;
wdenk2262cfe2002-11-18 00:14:45 +000086 int vector;
Graeme Russ3ef96de2008-09-07 07:08:42 +100087#ifdef CONFIG_PCI
wdenk7a8e9bed2003-05-31 18:35:21 +000088 struct pci_controller *pri_hose;
Graeme Russ3ef96de2008-09-07 07:08:42 +100089#endif
Graeme Russ83088af2011-11-08 02:33:15 +000090 if (done)
wdenk2262cfe2002-11-18 00:14:45 +000091 return 0;
Graeme Russ83088af2011-11-08 02:33:15 +000092
wdenk2262cfe2002-11-18 00:14:45 +000093 done = 1;
wdenk8bde7f72003-06-27 21:31:46 +000094
Graeme Russ067f9b12010-10-07 20:03:31 +110095 if (bios_size > 65536) {
wdenk8bde7f72003-06-27 21:31:46 +000096 printf("BIOS too large (%ld bytes, max is 65536)\n",
Graeme Russ83088af2011-11-08 02:33:15 +000097 bios_size);
wdenk2262cfe2002-11-18 00:14:45 +000098 return -1;
99 }
wdenk8bde7f72003-06-27 21:31:46 +0000100
Graeme Russ83088af2011-11-08 02:33:15 +0000101 memcpy(BIOS_BASE, (void *)bios_start, bios_size);
wdenk2262cfe2002-11-18 00:14:45 +0000102
103 /* clear bda */
104 memset(BIOS_DATA, 0, BIOS_DATA_SIZE);
wdenk8bde7f72003-06-27 21:31:46 +0000105
wdenk2262cfe2002-11-18 00:14:45 +0000106 /* enter some values to the bda */
107 writew(0x3f8, BIOS_DATA); /* com1 addr */
108 writew(0x2f8, BIOS_DATA+2); /* com2 addr */
109 writew(0x3e8, BIOS_DATA+4); /* com3 addr */
110 writew(0x2e8, BIOS_DATA+6); /* com4 addr */
111 writew(0x278, BIOS_DATA+8); /* lpt1 addr */
112 /*
113 * The kernel wants to read the base memory size
114 * from 40:13. Put a zero there to avoid an error message
115 */
116 writew(0, BIOS_DATA+0x13); /* base memory size */
117
wdenk8bde7f72003-06-27 21:31:46 +0000118
119 /* setup realmode interrupt vectors */
Graeme Russ83088af2011-11-08 02:33:15 +0000120 for (vector = 0; vector < NUMVECTS; vector++)
wdenk2262cfe2002-11-18 00:14:45 +0000121 setvector(vector, BIOS_CS, &rm_def_int);
wdenk8bde7f72003-06-27 21:31:46 +0000122
wdenk2262cfe2002-11-18 00:14:45 +0000123 setvector(0x00, BIOS_CS, &rm_int00);
124 setvector(0x01, BIOS_CS, &rm_int01);
125 setvector(0x02, BIOS_CS, &rm_int02);
126 setvector(0x03, BIOS_CS, &rm_int03);
127 setvector(0x04, BIOS_CS, &rm_int04);
128 setvector(0x05, BIOS_CS, &rm_int05);
129 setvector(0x06, BIOS_CS, &rm_int06);
130 setvector(0x07, BIOS_CS, &rm_int07);
131 setvector(0x08, BIOS_CS, &rm_int08);
132 setvector(0x09, BIOS_CS, &rm_int09);
133 setvector(0x0a, BIOS_CS, &rm_int0a);
134 setvector(0x0b, BIOS_CS, &rm_int0b);
135 setvector(0x0c, BIOS_CS, &rm_int0c);
136 setvector(0x0d, BIOS_CS, &rm_int0d);
137 setvector(0x0e, BIOS_CS, &rm_int0e);
138 setvector(0x0f, BIOS_CS, &rm_int0f);
139 setvector(0x10, BIOS_CS, &rm_int10);
140 setvector(0x11, BIOS_CS, &rm_int11);
141 setvector(0x12, BIOS_CS, &rm_int12);
142 setvector(0x13, BIOS_CS, &rm_int13);
143 setvector(0x14, BIOS_CS, &rm_int14);
144 setvector(0x15, BIOS_CS, &rm_int15);
145 setvector(0x16, BIOS_CS, &rm_int16);
146 setvector(0x17, BIOS_CS, &rm_int17);
147 setvector(0x18, BIOS_CS, &rm_int18);
148 setvector(0x19, BIOS_CS, &rm_int19);
149 setvector(0x1a, BIOS_CS, &rm_int1a);
150 setvector(0x1b, BIOS_CS, &rm_int1b);
151 setvector(0x1c, BIOS_CS, &rm_int1c);
152 setvector(0x1d, BIOS_CS, &rm_int1d);
153 setvector(0x1e, BIOS_CS, &rm_int1e);
154 setvector(0x1f, BIOS_CS, &rm_int1f);
155
wdenk7a8e9bed2003-05-31 18:35:21 +0000156 set_jmp_vector(0xfff0, &realmode_reset);
157 set_jmp_vector(0xfe6e, &realmode_pci_bios_call_entry);
wdenk8bde7f72003-06-27 21:31:46 +0000158
wdenk2262cfe2002-11-18 00:14:45 +0000159 /* fill in data area */
wdenk7a8e9bed2003-05-31 18:35:21 +0000160 RELOC_16_WORD(0xf000, ram_in_64kb_chunks) = gd->ram_size >> 16;
161 RELOC_16_WORD(0xf000, bios_equipment) = 0; /* FixMe */
wdenk8bde7f72003-06-27 21:31:46 +0000162
wdenk7a8e9bed2003-05-31 18:35:21 +0000163 /* If we assume only one PCI hose, this PCI hose
wdenk8bde7f72003-06-27 21:31:46 +0000164 * will own PCI bus #0, and the last PCI bus of
165 * that PCI hose will be the last PCI bus in the
166 * system.
wdenk7a8e9bed2003-05-31 18:35:21 +0000167 * (This, ofcause break on multi hose systems,
wdenk8bde7f72003-06-27 21:31:46 +0000168 * but our PCI BIOS only support one hose anyway)
wdenk7a8e9bed2003-05-31 18:35:21 +0000169 */
Graeme Russ3ef96de2008-09-07 07:08:42 +1000170#ifdef CONFIG_PCI
wdenk7a8e9bed2003-05-31 18:35:21 +0000171 pri_hose = pci_bus_to_hose(0);
172 if (NULL != pri_hose) {
wdenk8bde7f72003-06-27 21:31:46 +0000173 /* fill in last pci bus number for use by the realmode
wdenk7a8e9bed2003-05-31 18:35:21 +0000174 * PCI BIOS */
175 RELOC_16_BYTE(0xf000, pci_last_bus) = pri_hose->last_busno;
176 }
Graeme Russ3ef96de2008-09-07 07:08:42 +1000177#endif
wdenk2262cfe2002-11-18 00:14:45 +0000178 return 0;
179}