/*
* Copyright (c) 1999 Leo Weppelman. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Go look for a VGA card on the PCI-bus. This search is a
* stripped down version of the PCI-probe. It only looks on
* bus0 for VGA cards. The first card found is used.
*/
int
check_for_vga(bus_space_tag_t iot, bus_space_tag_t memt)
{
pci_chipset_tag_t pc = NULL; /* XXX */
bus_space_handle_t ioh_regs, memh_fb;
pcitag_t tag;
int device, found, maxndevs, i;
int got_ioh, got_memh, rv;
uint32_t id, class;
volatile uint8_t *regs;
uint8_t *fb;
const char *nbd = "NetBSD/Atari";
found = 0;
tag = 0;
id = 0;
rv = 0;
got_ioh = 0;
got_memh = 0;
maxndevs = pci_bus_maxdevs(pc, 0);
/*
* Map 8Kb of registers and 32Kb frame buffer.
* XXX: The way the registers are mapped here is plain wrong.
* We should try to pin-point the region down to 3[bcd]0 (see
* .../dev/ic/vga.c).
*/
if (bus_space_map(iot, 0, VGA_REG_SIZE, 0, &ioh_regs))
return 0;
got_ioh = 1;
tag = pci_make_tag(pc, 0, device, 0);
id = pci_conf_read(pc, tag, PCI_ID_REG);
if (id == 0 || id == 0xffffffff)
continue;
/*
* Check if we have some display device here...
*/
class = pci_conf_read(pc, tag, PCI_CLASS_REG);
i = 0;
if (PCI_CLASS(class) == PCI_CLASS_PREHISTORIC &&
PCI_SUBCLASS(class) == PCI_SUBCLASS_PREHISTORIC_VGA)
i = 1;
if (PCI_CLASS(class) == PCI_CLASS_DISPLAY &&
PCI_SUBCLASS(class) == PCI_SUBCLASS_DISPLAY_VGA)
i = 1;
if (i == 0)
continue;
#if _MILANHW_
/* Don't need to be more specific */
milan_vga_init(pc, tag, id, regs, fb);
found = 1;
#else
switch (id = PCI_PRODUCT(id)) {
/*
* XXX Make the inclusion of the cases dependent
* on config options!
*/
case PCI_PRODUCT_TSENG_ET6000:
case PCI_PRODUCT_TSENG_ET4000_W32P_A:
case PCI_PRODUCT_TSENG_ET4000_W32P_B:
case PCI_PRODUCT_TSENG_ET4000_W32P_C:
case PCI_PRODUCT_TSENG_ET4000_W32P_D:
tseng_init(pc, tag, id, regs, fb);
found = 1;
break;
case PCI_PRODUCT_ATI_RAGE_PRO_PCI_P:
ati_vga_init(pc, tag, id, regs, fb);
found = 1;
break;
default:
break;
}
#endif /* _MILANHW_ */
}
if (!found)
goto bad;
/*
* Assume the device is in CGA mode. Wscons expects this too...
*/
bus_space_unmap(memt, memh_fb, VGA_FB_SIZE);
if (bus_space_map(memt, 0xb8000, VGA_FB_SIZE, 0, &memh_fb)) {
got_memh = 0;
goto bad;
}
fb = bus_space_vaddr(memt, memh_fb);
/*
* Generic parts of the initialization...
*/
/* set ATC registers */
for (i = 0; i < 21; i++)
WAttr(regs, i, vga_atc[i]);
/* set DAC palette */
for (i = 0; i < 16; i++) {
vgaw(regs, VDAC_ADDRESS_W, vga_atc[i]);
vgaw(regs, VDAC_DATA, vga_dacpal[i * 3 + 0]);
vgaw(regs, VDAC_DATA, vga_dacpal[i * 3 + 1]);
vgaw(regs, VDAC_DATA, vga_dacpal[i * 3 + 2]);
}
loadfont(regs, fb);
#if NVGA_PCI > 0
/* use explicit WSDISPLAY_FONTENC_IBM font that MI vga(4) assumes */
vga_no_builtinfont = 1;
#endif
/*
* Clear the screen and print a message. The latter
* is of diagnostic/debug use only.
*/
for (i = 50 * 80; i >= 0; i -= 2) {
fb[i] = 0x20; fb[i+1] = 0x07;
}
for (i = 56; *nbd; i += 2)
fb[i] = *nbd++;
if (tags_valid) {
/* XXX: Are those arguments correct? Leo */
vga_cnattach(vga_iot, vga_memt, 8, 0);
}
}
#endif /* NVGA_PCI */
/*
* Generic VGA. Load the configured kernel font into the videomemory and
* place the card into textmode.
*/
static void
loadfont(volatile uint8_t *ba, uint8_t *fb)
/* ba: Register area KVA */
/* fb: Frame buffer KVA */
{
font_info *fd;
uint8_t *c, *f, tmp;
uint16_t z, y;
/*
* load text font into beginning of display memory. Each
* character cell is 32 bytes long (enough for 4 planes)
*/
for (z = 0, c = fb; z < 256 * 32; z++)
*c++ = 0;
c = (uint8_t *)(fb) + (32 * fd->font_lo);
f = fd->font_p;
z = fd->font_lo;
for (; z <= fd->font_hi; z++, c += (32 - fd->height))
for (y = 0; y < fd->height; y++) {
*c++ = *f++;
}