]> git.sur5r.net Git - u-boot/blob - arch/x86/lib/video_bios.c
cosmetic: checkpatch cleanup of arch/x86/lib/*.c
[u-boot] / arch / x86 / lib / video_bios.c
1 /*
2  * (C) Copyright 2002
3  * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
4  *
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 #include <common.h>
25 #include <pci.h>
26 #include <malloc.h>
27 #include <asm/ptrace.h>
28 #include <asm/realmode.h>
29 #include <asm/io.h>
30 #include <asm/pci.h>
31 #include "bios.h"
32
33 #undef PCI_BIOS_DEBUG
34 #undef VGA_BIOS_DEBUG
35
36 #ifdef  VGA_BIOS_DEBUG
37 #define PRINTF(fmt, args...)    printf(fmt, ##args)
38 #else
39 #define PRINTF(fmt, args...)
40 #endif
41
42 #ifdef CONFIG_PCI
43
44 #ifdef PCI_BIOS_DEBUG
45 void print_bios_bios_stat(void)
46 {
47         printf("16 bit functions:\n");
48         printf("pci_bios_present:                %d\n",
49                         RELOC_16_LONG(0xf000, num_pci_bios_present));
50         printf("pci_bios_find_device:            %d\n",
51                         RELOC_16_LONG(0xf000, num_pci_bios_find_device));
52         printf("pci_bios_find_class:             %d\n",
53                         RELOC_16_LONG(0xf000, num_pci_bios_find_class));
54         printf("pci_bios_generate_special_cycle: %d\n",
55                         RELOC_16_LONG(0xf000,
56                                       num_pci_bios_generate_special_cycle));
57         printf("pci_bios_read_cfg_byte:          %d\n",
58                         RELOC_16_LONG(0xf000, num_pci_bios_read_cfg_byte));
59         printf("pci_bios_read_cfg_word:          %d\n",
60                         RELOC_16_LONG(0xf000, num_pci_bios_read_cfg_word));
61         printf("pci_bios_read_cfg_dword:         %d\n",
62                         RELOC_16_LONG(0xf000, num_pci_bios_read_cfg_dword));
63         printf("pci_bios_write_cfg_byte:         %d\n",
64                         RELOC_16_LONG(0xf000, num_pci_bios_write_cfg_byte));
65         printf("pci_bios_write_cfg_word:         %d\n",
66                         RELOC_16_LONG(0xf000, num_pci_bios_write_cfg_word));
67         printf("pci_bios_write_cfg_dword:        %d\n",
68                         RELOC_16_LONG(0xf000, num_pci_bios_write_cfg_dword));
69         printf("pci_bios_get_irq_routing:        %d\n",
70                         RELOC_16_LONG(0xf000, num_pci_bios_get_irq_routing));
71         printf("pci_bios_set_irq:                %d\n",
72                         RELOC_16_LONG(0xf000, num_pci_bios_set_irq));
73         printf("pci_bios_unknown_function:       %d\n",
74                         RELOC_16_LONG(0xf000, num_pci_bios_unknown_function));
75
76 }
77 #endif
78
79 #ifdef CONFIG_VIDEO
80
81 #define PCI_CLASS_VIDEO                 3
82 #define PCI_CLASS_VIDEO_STD             0
83 #define PCI_CLASS_VIDEO_PROG_IF_VGA     0
84
85 DEFINE_PCI_DEVICE_TABLE(supported) = {
86         {PCI_VIDEO_VENDOR_ID, PCI_VIDEO_DEVICE_ID},
87         {}
88 };
89
90 static u32 probe_pci_video(void)
91 {
92         struct pci_controller *hose;
93         pci_dev_t devbusfn = pci_find_devices(supported, 0);
94
95         if ((devbusfn != -1)) {
96                 u32 old;
97                 u32 addr;
98
99                 /* PCI video device detected */
100                 printf("Found PCI VGA device at %02x.%02x.%x\n",
101                        PCI_BUS(devbusfn),
102                        PCI_DEV(devbusfn),
103                        PCI_FUNC(devbusfn));
104
105                 /* Enable I/O decoding as well, PCI viudeo boards
106                  * support I/O accesses, but they provide no
107                  * bar register for this since the ports are fixed.
108                  */
109                 pci_write_config_word(devbusfn,
110                                       PCI_COMMAND,
111                                       PCI_COMMAND_MEMORY |
112                                       PCI_COMMAND_IO |
113                                       PCI_COMMAND_MASTER);
114
115                 /* Test the ROM decoder, do the device support a rom? */
116                 pci_read_config_dword(devbusfn, PCI_ROM_ADDRESS, &old);
117                 pci_write_config_dword(devbusfn, PCI_ROM_ADDRESS,
118                                        (u32)PCI_ROM_ADDRESS_MASK);
119                 pci_read_config_dword(devbusfn, PCI_ROM_ADDRESS, &addr);
120                 pci_write_config_dword(devbusfn, PCI_ROM_ADDRESS, old);
121
122                 if (!addr) {
123                         printf("PCI VGA have no ROM?\n");
124                         return 0;
125                 }
126
127                 /* device have a rom */
128                 if (pci_shadow_rom(devbusfn, (void *)0xc0000)) {
129                         printf("Shadowing of PCI VGA BIOS failed\n");
130                         return 0;
131                 }
132
133                 /* Now enable lagacy VGA port access */
134                 hose = pci_bus_to_hose(PCI_BUS(devbusfn));
135                 if (pci_enable_legacy_video_ports(hose)) {
136                         printf("PCI VGA enable failed\n");
137                         return 0;
138                 }
139
140
141                 /* return the pci device info, that we'll need later */
142                 return PCI_BUS(devbusfn) << 8 |
143                         PCI_DEV(devbusfn) << 3 | (PCI_FUNC(devbusfn) & 7);
144         }
145
146         return 0;
147 }
148
149 static int probe_isa_video(void)
150 {
151         u32 ptr;
152         char *buf;
153
154         ptr = isa_map_rom(0xc0000, 0x8000);
155
156         if (!ptr)
157                 return -1;
158
159         buf = malloc(0x8000);
160         if (!buf) {
161                 isa_unmap_rom(ptr);
162                 return -1;
163         }
164
165         if (readw(ptr) != 0xaa55) {
166                 free(buf);
167                 isa_unmap_rom(ptr);
168                 return -1;
169         }
170
171         /* shadow the rom */
172         memcpy(buf, (void *)ptr, 0x8000);
173         isa_unmap_rom(ptr);
174         memcpy((void *)0xc0000, buf, 0x8000);
175
176         free(buf);
177
178         return 0;
179 }
180
181 int video_bios_init(void)
182 {
183         struct pt_regs regs;
184         int size;
185         int i;
186         u8 sum;
187
188         /* clear the video bios area in case we warmbooted */
189         memset((void *)0xc0000, 0, 0x8000);
190         memset(&regs, 0, sizeof(struct pt_regs));
191
192         if (probe_isa_video())
193                 /* No ISA board found, try the PCI bus */
194                 regs.eax = probe_pci_video();
195
196         /* Did we succeed in mapping any video bios */
197         if (readw(0xc0000) == 0xaa55) {
198                 PRINTF("Found video bios signature\n");
199                 size = readb(0xc0002) * 512;
200                 PRINTF("size %d\n", size);
201                 sum = 0;
202
203                 for (i = 0; i < size; i++)
204                         sum += readb(0xc0000 + i);
205
206                 PRINTF("Checksum is %sOK\n", sum ? "NOT " : "");
207
208                 if (sum)
209                         return 1;
210
211                 /*
212                  * Some video bioses (ATI Mach64) seem to think that
213                  * the original int 10 handler is always at
214                  * 0xf000:0xf065 , place an iret instruction there
215                  */
216                 writeb(0xcf, 0xff065);
217
218                 regs.esp = 0x8000;
219                 regs.xss = 0x2000;
220                 enter_realmode(0xc000, 3, &regs, &regs);
221
222                 PRINTF("INT 0x10 vector after:  %04x:%04x\n",
223                        readw(0x42), readw(0x40));
224                 PRINTF("BIOS returned %scarry\n",
225                        regs.eflags & 0x00000001 ? "" : "NOT ");
226 #ifdef PCI_BIOS_DEBUG
227                 print_bios_bios_stat();
228 #endif
229                 return regs.eflags & 0x00000001;
230
231         }
232
233         return 1;
234
235 }
236 #endif
237 #endif