Home | History | Annotate | Line # | Download | only in pci
pci_vga.c revision 1.11.78.1
      1  1.11.78.1   yamt /*	$NetBSD: pci_vga.c,v 1.11.78.1 2009/05/04 08:10:48 yamt Exp $	*/
      2        1.1    leo 
      3        1.1    leo /*
      4        1.1    leo  * Copyright (c) 1999 Leo Weppelman.  All rights reserved.
      5        1.1    leo  *
      6        1.1    leo  * Redistribution and use in source and binary forms, with or without
      7        1.1    leo  * modification, are permitted provided that the following conditions
      8        1.1    leo  * are met:
      9        1.1    leo  * 1. Redistributions of source code must retain the above copyright
     10        1.1    leo  *    notice, this list of conditions and the following disclaimer.
     11        1.1    leo  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1    leo  *    notice, this list of conditions and the following disclaimer in the
     13        1.1    leo  *    documentation and/or other materials provided with the distribution.
     14        1.1    leo  * 3. All advertising materials mentioning features or use of this software
     15        1.1    leo  *    must display the following acknowledgement:
     16        1.1    leo  *	This product includes software developed by Leo Weppelman.
     17        1.1    leo  * 4. The name of the author may not be used to endorse or promote products
     18        1.1    leo  *    derived from this software without specific prior written permission.
     19        1.1    leo  *
     20        1.1    leo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21        1.1    leo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22        1.1    leo  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23        1.1    leo  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24        1.1    leo  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25        1.1    leo  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26        1.1    leo  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27        1.1    leo  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28        1.1    leo  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29        1.1    leo  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30        1.1    leo  */
     31        1.9  lukem 
     32        1.9  lukem #include <sys/cdefs.h>
     33  1.11.78.1   yamt __KERNEL_RCSID(0, "$NetBSD: pci_vga.c,v 1.11.78.1 2009/05/04 08:10:48 yamt Exp $");
     34        1.9  lukem 
     35        1.1    leo #include <sys/param.h>
     36        1.1    leo #include <sys/queue.h>
     37        1.1    leo #include <sys/systm.h>
     38        1.1    leo #include <dev/pci/pcireg.h>
     39        1.1    leo #include <dev/pci/pcivar.h>
     40        1.1    leo #include <dev/pci/pcidevs.h>
     41        1.1    leo #include <atari/pci/pci_vga.h>
     42        1.1    leo #include <atari/dev/grf_etreg.h>
     43        1.1    leo #include <atari/include/iomap.h>
     44        1.1    leo 
     45        1.1    leo #include <atari/dev/font.h>
     46        1.1    leo 
     47        1.6    leo #include "vga_pci.h"
     48        1.4    leo #if NVGA_PCI > 0
     49        1.4    leo #include <dev/cons.h>
     50        1.4    leo #include <dev/ic/mc6845reg.h>
     51        1.4    leo #include <dev/ic/pcdisplayvar.h>
     52        1.4    leo #include <dev/ic/vgareg.h>
     53        1.4    leo #include <dev/ic/vgavar.h>
     54        1.4    leo #endif
     55        1.4    leo 
     56        1.1    leo static void loadfont(volatile u_char *, u_char *fb);
     57        1.1    leo 
     58        1.1    leo /* XXX: Shouldn't these be in font.h???? */
     59        1.1    leo extern font_info	font_info_8x8;
     60        1.1    leo extern font_info	font_info_8x16;
     61        1.1    leo 
     62        1.1    leo /* Console colors */
     63        1.1    leo static u_char conscolors[3][3] = {	/* background, foreground, hilite */
     64        1.1    leo 	{0x0, 0x0, 0x0}, {0x30, 0x30, 0x30}, { 0x3f,  0x3f,  0x3f}
     65        1.1    leo };
     66        1.1    leo 
     67        1.4    leo static bus_space_tag_t	vga_iot, vga_memt;
     68        1.4    leo static int		tags_valid = 0;
     69        1.3    leo 
     70        1.3    leo #define		VGA_REG_SIZE	(8*1024)
     71        1.3    leo #define		VGA_FB_SIZE	(32*1024)
     72        1.3    leo 
     73        1.1    leo /*
     74        1.1    leo  * Go look for a VGA card on the PCI-bus. This search is a
     75        1.1    leo  * stripped down version of the PCI-probe. It only looks on
     76        1.1    leo  * bus0 for VGA cards. The first card found is used.
     77        1.1    leo  */
     78        1.1    leo int
     79  1.11.78.1   yamt check_for_vga(bus_space_tag_t iot, bus_space_tag_t memt)
     80        1.1    leo {
     81        1.1    leo 	pci_chipset_tag_t	pc = NULL; /* XXX */
     82        1.3    leo 	bus_space_handle_t	ioh_regs, memh_fb;
     83        1.1    leo 	pcitag_t		tag;
     84        1.1    leo 	int			device, found, id, maxndevs, i, j;
     85        1.3    leo 	int			class, got_ioh, got_memh, rv;
     86        1.1    leo 	volatile u_char		*regs;
     87        1.1    leo 	u_char			*fb;
     88       1.10     he 	const char		*nbd = "NetBSD/Atari";
     89        1.1    leo 
     90        1.1    leo 	found    = 0;
     91        1.1    leo 	tag      = 0;
     92        1.1    leo 	id       = 0;
     93        1.3    leo 	rv	 = 0;
     94        1.3    leo 	got_ioh	 = 0;
     95        1.3    leo 	got_memh = 0;
     96        1.1    leo 	maxndevs = pci_bus_maxdevs(pc, 0);
     97        1.1    leo 
     98        1.1    leo 	/*
     99        1.3    leo 	 * Map 8Kb of registers and 32Kb frame buffer.
    100        1.3    leo 	 * XXX: The way the registers are mapped here is plain wrong.
    101        1.3    leo 	 *      We should try to pin-point the region down to 3[bcd]0 (see
    102        1.3    leo 	 *      .../dev/ic/vga.c).
    103        1.1    leo 	 */
    104        1.3    leo 	if (bus_space_map(iot, 0, VGA_REG_SIZE, 0, &ioh_regs))
    105        1.3    leo 		return 0;
    106        1.3    leo 	got_ioh = 1;
    107        1.3    leo 
    108        1.3    leo 	if (bus_space_map(memt, 0xa0000, VGA_FB_SIZE, 0, &memh_fb))
    109        1.3    leo 		goto bad;
    110        1.3    leo 	got_memh = 1;
    111        1.3    leo 	regs = bus_space_vaddr(iot, ioh_regs);
    112        1.3    leo 	fb   = bus_space_vaddr(memt, memh_fb);
    113        1.1    leo 
    114        1.1    leo 	for (device = 0; !found && (device < maxndevs); device++) {
    115        1.1    leo 
    116        1.1    leo 		tag = pci_make_tag(pc, 0, device, 0);
    117        1.1    leo 		id  = pci_conf_read(pc, tag, PCI_ID_REG);
    118        1.1    leo 		if (id == 0 || id == 0xffffffff)
    119        1.1    leo 			continue;
    120        1.3    leo 
    121        1.3    leo 		/*
    122        1.3    leo 		 * Check if we have some display device here...
    123        1.3    leo 		 */
    124        1.3    leo 		class = pci_conf_read(pc, tag, PCI_CLASS_REG);
    125        1.3    leo 		i = 0;
    126        1.3    leo 		if (PCI_CLASS(class) == PCI_CLASS_PREHISTORIC &&
    127        1.3    leo 		    PCI_SUBCLASS(class) == PCI_SUBCLASS_PREHISTORIC_VGA)
    128        1.3    leo 			i = 1;
    129        1.3    leo 		if (PCI_CLASS(class) == PCI_CLASS_DISPLAY &&
    130        1.3    leo 		    PCI_SUBCLASS(class) == PCI_SUBCLASS_DISPLAY_VGA)
    131        1.3    leo 			i = 1;
    132        1.3    leo 		if (i == 0)
    133        1.3    leo 			continue;
    134        1.3    leo 
    135        1.5    leo #if _MILANHW_
    136        1.5    leo 		/* Don't need to be more specific */
    137        1.5    leo 		milan_vga_init(pc, tag, id, regs, fb);
    138        1.5    leo 		found = 1;
    139        1.5    leo #else
    140        1.1    leo 		switch (id = PCI_PRODUCT(id)) {
    141        1.1    leo 
    142        1.1    leo 			/*
    143        1.1    leo 			 * XXX Make the inclusion of the cases dependend
    144        1.1    leo 			 *     on config options!
    145        1.1    leo 			 */
    146        1.1    leo 			case PCI_PRODUCT_TSENG_ET6000:
    147        1.1    leo 			case PCI_PRODUCT_TSENG_ET4000_W32P_A:
    148        1.1    leo 			case PCI_PRODUCT_TSENG_ET4000_W32P_B:
    149        1.1    leo 			case PCI_PRODUCT_TSENG_ET4000_W32P_C:
    150        1.1    leo 			case PCI_PRODUCT_TSENG_ET4000_W32P_D:
    151        1.1    leo 				tseng_init(pc, tag, id, regs, fb);
    152        1.7    leo 				found = 1;
    153        1.7    leo 				break;
    154        1.8    leo 			case PCI_PRODUCT_ATI_RAGE_PRO_PCI_P:
    155        1.7    leo 				ati_vga_init(pc, tag, id, regs, fb);
    156        1.1    leo 				found = 1;
    157        1.1    leo 				break;
    158        1.1    leo 			default:
    159        1.1    leo 				break;
    160        1.1    leo 		}
    161        1.5    leo #endif /* _MILANHW_ */
    162        1.1    leo 	}
    163        1.1    leo 	if (!found)
    164        1.3    leo 		goto bad;
    165        1.1    leo 
    166        1.1    leo 	/*
    167        1.2    leo 	 * Assume the device is in CGA mode. Wscons expects this too...
    168        1.2    leo 	 */
    169        1.3    leo 	bus_space_unmap(memt, memh_fb, VGA_FB_SIZE);
    170        1.3    leo 	if (bus_space_map(memt, 0xb8000, VGA_FB_SIZE, 0, &memh_fb)) {
    171        1.3    leo 		got_memh = 0;
    172        1.3    leo 		goto bad;
    173        1.3    leo 	}
    174        1.3    leo 	fb = bus_space_vaddr(memt, memh_fb);
    175        1.2    leo 
    176        1.2    leo 	/*
    177        1.1    leo 	 * Generic parts of the initialization...
    178        1.1    leo 	 */
    179        1.1    leo 
    180        1.1    leo 	/* B&W colors */
    181        1.1    leo 	vgaw(regs, VDAC_ADDRESS_W, 0);
    182        1.1    leo 	for (i = 0; i < 256; i++) {
    183        1.1    leo 		j = (i & 1) ? ((i > 7) ? 2 : 1) : 0;
    184        1.1    leo 		vgaw(regs, VDAC_DATA, conscolors[j][0]);
    185        1.1    leo 		vgaw(regs, VDAC_DATA, conscolors[j][1]);
    186        1.1    leo 		vgaw(regs, VDAC_DATA, conscolors[j][2]);
    187        1.1    leo 	}
    188        1.1    leo 
    189        1.1    leo 	loadfont(regs, fb);
    190        1.1    leo 
    191        1.1    leo 	/*
    192        1.1    leo 	 * Clear the screen and print a message. The latter
    193        1.1    leo 	 * is of diagnostic/debug use only.
    194        1.1    leo 	 */
    195        1.1    leo 	for (i = 50 * 80; i >= 0; i -= 2) {
    196        1.1    leo 		fb[i] = 0x20; fb[i+1] = 0x07;
    197        1.1    leo 	}
    198        1.1    leo 	for (i = 56; *nbd; i += 2)
    199        1.1    leo 		fb[i] = *nbd++;
    200        1.1    leo 
    201        1.3    leo 	rv = 1;
    202        1.3    leo 	vga_iot  = iot;
    203        1.3    leo 	vga_memt = memt;
    204        1.3    leo 	rv = tags_valid = 1;
    205        1.3    leo 
    206        1.3    leo bad:
    207        1.3    leo 	if (got_memh)
    208        1.3    leo 		bus_space_unmap(memt, memh_fb, VGA_FB_SIZE);
    209        1.3    leo 	if (got_ioh)
    210        1.3    leo 		bus_space_unmap(iot, ioh_regs, VGA_REG_SIZE);
    211        1.3    leo 	return (rv);
    212        1.1    leo }
    213        1.4    leo 
    214        1.4    leo #if NVGA_PCI > 0
    215        1.4    leo void vgacnprobe(struct consdev *);
    216        1.4    leo void vgacninit(struct consdev *);
    217        1.4    leo 
    218        1.4    leo void
    219  1.11.78.1   yamt vgacnprobe(struct consdev *cp)
    220        1.4    leo {
    221        1.4    leo 	if (tags_valid)
    222        1.4    leo 		cp->cn_pri = CN_NORMAL;
    223        1.4    leo }
    224        1.4    leo 
    225        1.4    leo void
    226  1.11.78.1   yamt vgacninit(struct consdev *cp)
    227        1.4    leo {
    228        1.4    leo 	if (tags_valid) {
    229        1.4    leo 		/* XXX: Are those arguments correct? Leo */
    230        1.4    leo 		vga_cnattach(vga_iot, vga_memt, 8, 0);
    231        1.4    leo 	}
    232        1.4    leo }
    233        1.4    leo #endif /* NVGA_PCI */
    234        1.1    leo 
    235        1.1    leo /*
    236        1.1    leo  * Generic VGA. Load the configured kernel font into the videomemory and
    237        1.1    leo  * place the card into textmode.
    238        1.1    leo  */
    239        1.1    leo static void
    240  1.11.78.1   yamt loadfont(volatile u_char *ba, u_char *fb)
    241  1.11.78.1   yamt 	/* ba:	 Register area KVA */
    242  1.11.78.1   yamt 	/* fb:	 Frame buffer	KVA  */
    243        1.1    leo {
    244        1.1    leo 	font_info	*fd;
    245        1.1    leo 	u_char		*c, *f, tmp;
    246        1.1    leo 	u_short		z, y;
    247        1.1    leo 
    248        1.1    leo #if defined(KFONT_8X8)
    249        1.1    leo 	fd = &font_info_8x8;
    250        1.1    leo #else
    251        1.1    leo 	fd = &font_info_8x16;
    252        1.1    leo #endif
    253        1.1    leo 
    254        1.1    leo 	WAttr(ba, 0x20 | ACT_ID_ATTR_MODE_CNTL, 0x0a);
    255        1.1    leo 	WSeq(ba, SEQ_ID_MAP_MASK,	 0x04);
    256        1.1    leo 	WSeq(ba, SEQ_ID_MEMORY_MODE,	 0x06);
    257        1.1    leo 	WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x02);
    258        1.1    leo 	WGfx(ba, GCT_ID_GRAPHICS_MODE,	 0x00);
    259        1.2    leo 	WGfx(ba, GCT_ID_MISC,		 0x0c);
    260        1.1    leo 
    261        1.1    leo 	/*
    262        1.1    leo 	 * load text font into beginning of display memory. Each
    263        1.1    leo 	 * character cell is 32 bytes long (enough for 4 planes)
    264        1.1    leo 	 */
    265        1.1    leo 	for (z = 0, c = fb; z < 256 * 32; z++)
    266        1.1    leo 		*c++ = 0;
    267        1.1    leo 
    268        1.1    leo 	c = (unsigned char *) (fb) + (32 * fd->font_lo);
    269        1.1    leo 	f = fd->font_p;
    270        1.1    leo 	z = fd->font_lo;
    271        1.1    leo 	for (; z <= fd->font_hi; z++, c += (32 - fd->height))
    272        1.1    leo 		for (y = 0; y < fd->height; y++) {
    273        1.1    leo 			*c++ = *f++;
    274        1.1    leo 		}
    275        1.1    leo 
    276        1.1    leo 	/*
    277        1.1    leo 	 * Odd/Even addressing
    278        1.1    leo 	 */
    279        1.1    leo 	WSeq(ba, SEQ_ID_MAP_MASK,	 0x03);
    280        1.1    leo 	WSeq(ba, SEQ_ID_MEMORY_MODE,	 0x03);
    281        1.1    leo 	WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
    282        1.1    leo 	WGfx(ba, GCT_ID_GRAPHICS_MODE,	 0x10);
    283        1.2    leo 	WGfx(ba, GCT_ID_MISC,		 0x0e);
    284        1.1    leo 
    285        1.1    leo 	/*
    286        1.1    leo 	 * Font height + underline location
    287        1.1    leo 	 */
    288        1.1    leo 	tmp = RCrt(ba, CRT_ID_MAX_ROW_ADDRESS) & 0xe0;
    289        1.1    leo 	WCrt(ba, CRT_ID_MAX_ROW_ADDRESS, tmp | (fd->height - 1));
    290        1.1    leo 	tmp = RCrt(ba, CRT_ID_UNDERLINE_LOC)   & 0xe0;
    291        1.1    leo 	WCrt(ba, CRT_ID_UNDERLINE_LOC,   tmp | (fd->height - 1));
    292        1.1    leo 
    293        1.1    leo 	/*
    294        1.1    leo 	 * Cursor setup
    295        1.1    leo 	 */
    296        1.1    leo 	WCrt(ba, CRT_ID_CURSOR_START   , 0x00);
    297        1.1    leo 	WCrt(ba, CRT_ID_CURSOR_END     , fd->height - 1);
    298        1.1    leo 	WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
    299        1.1    leo 	WCrt(ba, CRT_ID_CURSOR_LOC_LOW , 0x00);
    300        1.1    leo 
    301        1.1    leo 	/*
    302        1.1    leo 	 * Enter text mode
    303        1.1    leo 	 */
    304        1.1    leo 	WCrt(ba, CRT_ID_MODE_CONTROL   , 0xa3);
    305        1.1    leo 	WAttr(ba, ACT_ID_ATTR_MODE_CNTL | 0x20, 0x0a);
    306        1.1    leo }
    307