1 /* $NetBSD: pci_vga.c,v 1.13 2009/03/14 21:04:06 dsl Exp $ */
4 * Copyright (c) 1999 Leo Weppelman. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __KERNEL_RCSID(0, "$NetBSD: pci_vga.c,v 1.13 2009/03/14 21:04:06 dsl Exp $");
30 #include <sys/param.h>
31 #include <sys/queue.h>
32 #include <sys/systm.h>
33 #include <dev/pci/pcireg.h>
34 #include <dev/pci/pcivar.h>
35 #include <dev/pci/pcidevs.h>
36 #include <atari/pci/pci_vga.h>
37 #include <atari/dev/grf_etreg.h>
38 #include <atari/include/iomap.h>
40 #include <atari/dev/font.h>
45 #include <dev/ic/mc6845reg.h>
46 #include <dev/ic/pcdisplayvar.h>
47 #include <dev/ic/vgareg.h>
48 #include <dev/ic/vgavar.h>
51 static void loadfont(volatile u_char
*, u_char
*fb
);
53 /* XXX: Shouldn't these be in font.h???? */
54 extern font_info font_info_8x8
;
55 extern font_info font_info_8x16
;
58 static u_char conscolors
[3][3] = { /* background, foreground, hilite */
59 {0x0, 0x0, 0x0}, {0x30, 0x30, 0x30}, { 0x3f, 0x3f, 0x3f}
62 static bus_space_tag_t vga_iot
, vga_memt
;
63 static int tags_valid
= 0;
65 #define VGA_REG_SIZE (8*1024)
66 #define VGA_FB_SIZE (32*1024)
69 * Go look for a VGA card on the PCI-bus. This search is a
70 * stripped down version of the PCI-probe. It only looks on
71 * bus0 for VGA cards. The first card found is used.
74 check_for_vga(bus_space_tag_t iot
, bus_space_tag_t memt
)
76 pci_chipset_tag_t pc
= NULL
; /* XXX */
77 bus_space_handle_t ioh_regs
, memh_fb
;
79 int device
, found
, id
, maxndevs
, i
, j
;
80 int class, got_ioh
, got_memh
, rv
;
81 volatile u_char
*regs
;
83 const char *nbd
= "NetBSD/Atari";
91 maxndevs
= pci_bus_maxdevs(pc
, 0);
94 * Map 8Kb of registers and 32Kb frame buffer.
95 * XXX: The way the registers are mapped here is plain wrong.
96 * We should try to pin-point the region down to 3[bcd]0 (see
99 if (bus_space_map(iot
, 0, VGA_REG_SIZE
, 0, &ioh_regs
))
103 if (bus_space_map(memt
, 0xa0000, VGA_FB_SIZE
, 0, &memh_fb
))
106 regs
= bus_space_vaddr(iot
, ioh_regs
);
107 fb
= bus_space_vaddr(memt
, memh_fb
);
109 for (device
= 0; !found
&& (device
< maxndevs
); device
++) {
111 tag
= pci_make_tag(pc
, 0, device
, 0);
112 id
= pci_conf_read(pc
, tag
, PCI_ID_REG
);
113 if (id
== 0 || id
== 0xffffffff)
117 * Check if we have some display device here...
119 class = pci_conf_read(pc
, tag
, PCI_CLASS_REG
);
121 if (PCI_CLASS(class) == PCI_CLASS_PREHISTORIC
&&
122 PCI_SUBCLASS(class) == PCI_SUBCLASS_PREHISTORIC_VGA
)
124 if (PCI_CLASS(class) == PCI_CLASS_DISPLAY
&&
125 PCI_SUBCLASS(class) == PCI_SUBCLASS_DISPLAY_VGA
)
131 /* Don't need to be more specific */
132 milan_vga_init(pc
, tag
, id
, regs
, fb
);
135 switch (id
= PCI_PRODUCT(id
)) {
138 * XXX Make the inclusion of the cases dependend
141 case PCI_PRODUCT_TSENG_ET6000
:
142 case PCI_PRODUCT_TSENG_ET4000_W32P_A
:
143 case PCI_PRODUCT_TSENG_ET4000_W32P_B
:
144 case PCI_PRODUCT_TSENG_ET4000_W32P_C
:
145 case PCI_PRODUCT_TSENG_ET4000_W32P_D
:
146 tseng_init(pc
, tag
, id
, regs
, fb
);
149 case PCI_PRODUCT_ATI_RAGE_PRO_PCI_P
:
150 ati_vga_init(pc
, tag
, id
, regs
, fb
);
156 #endif /* _MILANHW_ */
162 * Assume the device is in CGA mode. Wscons expects this too...
164 bus_space_unmap(memt
, memh_fb
, VGA_FB_SIZE
);
165 if (bus_space_map(memt
, 0xb8000, VGA_FB_SIZE
, 0, &memh_fb
)) {
169 fb
= bus_space_vaddr(memt
, memh_fb
);
172 * Generic parts of the initialization...
176 vgaw(regs
, VDAC_ADDRESS_W
, 0);
177 for (i
= 0; i
< 256; i
++) {
178 j
= (i
& 1) ? ((i
> 7) ? 2 : 1) : 0;
179 vgaw(regs
, VDAC_DATA
, conscolors
[j
][0]);
180 vgaw(regs
, VDAC_DATA
, conscolors
[j
][1]);
181 vgaw(regs
, VDAC_DATA
, conscolors
[j
][2]);
187 * Clear the screen and print a message. The latter
188 * is of diagnostic/debug use only.
190 for (i
= 50 * 80; i
>= 0; i
-= 2) {
191 fb
[i
] = 0x20; fb
[i
+1] = 0x07;
193 for (i
= 56; *nbd
; i
+= 2)
203 bus_space_unmap(memt
, memh_fb
, VGA_FB_SIZE
);
205 bus_space_unmap(iot
, ioh_regs
, VGA_REG_SIZE
);
210 void vgacnprobe(struct consdev
*);
211 void vgacninit(struct consdev
*);
214 vgacnprobe(struct consdev
*cp
)
217 cp
->cn_pri
= CN_NORMAL
;
221 vgacninit(struct consdev
*cp
)
224 /* XXX: Are those arguments correct? Leo */
225 vga_cnattach(vga_iot
, vga_memt
, 8, 0);
228 #endif /* NVGA_PCI */
231 * Generic VGA. Load the configured kernel font into the videomemory and
232 * place the card into textmode.
235 loadfont(volatile u_char
*ba
, u_char
*fb
)
236 /* ba: Register area KVA */
237 /* fb: Frame buffer KVA */
243 #if defined(KFONT_8X8)
246 fd
= &font_info_8x16
;
249 WAttr(ba
, 0x20 | ACT_ID_ATTR_MODE_CNTL
, 0x0a);
250 WSeq(ba
, SEQ_ID_MAP_MASK
, 0x04);
251 WSeq(ba
, SEQ_ID_MEMORY_MODE
, 0x06);
252 WGfx(ba
, GCT_ID_READ_MAP_SELECT
, 0x02);
253 WGfx(ba
, GCT_ID_GRAPHICS_MODE
, 0x00);
254 WGfx(ba
, GCT_ID_MISC
, 0x0c);
257 * load text font into beginning of display memory. Each
258 * character cell is 32 bytes long (enough for 4 planes)
260 for (z
= 0, c
= fb
; z
< 256 * 32; z
++)
263 c
= (unsigned char *) (fb
) + (32 * fd
->font_lo
);
266 for (; z
<= fd
->font_hi
; z
++, c
+= (32 - fd
->height
))
267 for (y
= 0; y
< fd
->height
; y
++) {
272 * Odd/Even addressing
274 WSeq(ba
, SEQ_ID_MAP_MASK
, 0x03);
275 WSeq(ba
, SEQ_ID_MEMORY_MODE
, 0x03);
276 WGfx(ba
, GCT_ID_READ_MAP_SELECT
, 0x00);
277 WGfx(ba
, GCT_ID_GRAPHICS_MODE
, 0x10);
278 WGfx(ba
, GCT_ID_MISC
, 0x0e);
281 * Font height + underline location
283 tmp
= RCrt(ba
, CRT_ID_MAX_ROW_ADDRESS
) & 0xe0;
284 WCrt(ba
, CRT_ID_MAX_ROW_ADDRESS
, tmp
| (fd
->height
- 1));
285 tmp
= RCrt(ba
, CRT_ID_UNDERLINE_LOC
) & 0xe0;
286 WCrt(ba
, CRT_ID_UNDERLINE_LOC
, tmp
| (fd
->height
- 1));
291 WCrt(ba
, CRT_ID_CURSOR_START
, 0x00);
292 WCrt(ba
, CRT_ID_CURSOR_END
, fd
->height
- 1);
293 WCrt(ba
, CRT_ID_CURSOR_LOC_HIGH
, 0x00);
294 WCrt(ba
, CRT_ID_CURSOR_LOC_LOW
, 0x00);
299 WCrt(ba
, CRT_ID_MODE_CONTROL
, 0xa3);
300 WAttr(ba
, ACT_ID_ATTR_MODE_CNTL
| 0x20, 0x0a);