move probe and setup code into common functions. always probe (i.e.

even if PCI and the IDs are right), just for sanity, before declaring
success.  Split the single 0x3b0 -> 0x3df allocation into three seperate
ones: 0x3b0 -> 0x3bc (leaving the 4 ports available for lpt),
0x3c0 -> 0x3cf, and 0x3d0 -> 0x3df.  The former chunk has to be split
off if the lpt can exist there, and it's sort-of pretty to have each
group (based on second hex digit) have its own handle.
This commit is contained in:
cgd 1996-11-23 06:06:43 +00:00
parent ae3ad75501
commit 335c1af878
5 changed files with 108 additions and 98 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vga.c,v 1.1 1996/11/19 04:38:32 cgd Exp $ */
/* $NetBSD: vga.c,v 1.2 1996/11/23 06:06:43 cgd Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@ -36,8 +36,8 @@
#include <alpha/wscons/wsconsvar.h>
#include <alpha/common/vgavar.h>
#define VGA_6845_ADDR 0x24
#define VGA_6845_DATA 0x25
#define VGA_IO_D_6845_ADDR 0x4
#define VGA_IO_D_6845_DATA 0x5
struct cfdriver vga_cd = {
NULL, "vga", DV_DULL,
@ -67,24 +67,73 @@ static int vgammap __P((void *, off_t, int));
* The following functions implement back-end configuration grabbing
* and attachment.
*/
int
vga_common_probe(iot, memt)
bus_space_tag_t iot, memt;
{
bus_space_handle_t ioh_b, ioh_c, ioh_d, memh;
u_int16_t vgadata;
int gotio_b, gotio_c, gotio_d, gotmem, rv;
gotio_b = gotio_c = gotio_d = gotmem = rv = 0;
if (bus_space_map(iot, 0x3b0, 0xc, 0, &ioh_b))
goto bad;
gotio_b = 1;
if (bus_space_map(iot, 0x3c0, 0x10, 0, &ioh_c))
goto bad;
gotio_c = 1;
if (bus_space_map(iot, 0x3d0, 0x10, 0, &ioh_d))
goto bad;
gotio_d = 1;
if (bus_space_map(memt, 0xb8000, 0x8000, 0, &memh))
goto bad;
gotmem = 1;
vgadata = bus_space_read_2(memt, memh, 0);
bus_space_write_2(memt, memh, 0, 0xa55a);
rv = (bus_space_read_2(memt, memh, 0) == 0xa55a);
bus_space_write_2(memt, memh, 0, vgadata);
bad:
if (gotio_b)
bus_space_unmap(iot, ioh_b, 0xc);
if (gotio_c)
bus_space_unmap(iot, ioh_c, 0x10);
if (gotio_d)
bus_space_unmap(iot, ioh_d, 0x10);
if (gotmem)
bus_space_unmap(memt, memh, 0x8000);
return (rv);
}
void
vga_getconfig(vc)
vga_common_setup(iot, memt, vc)
bus_space_tag_t iot, memt;
struct vga_config *vc;
{
bus_space_tag_t iot;
bus_space_handle_t ioh;
int cpos;
iot = vc->vc_iot;
ioh = vc->vc_ioh;
vc->vc_iot = iot;
vc->vc_memt = memt;
if (bus_space_map(vc->vc_iot, 0x3b0, 0xc, 0, &vc->vc_ioh_b))
panic("vga_common_setup: couldn't map io b");
if (bus_space_map(vc->vc_iot, 0x3c0, 0x10, 0, &vc->vc_ioh_c))
panic("vga_common_setup: couldn't map io c");
if (bus_space_map(vc->vc_iot, 0x3d0, 0x10, 0, &vc->vc_ioh_d))
panic("vga_common_setup: couldn't map io d");
if (bus_space_map(vc->vc_memt, 0xb8000, 0x8000, 0, &vc->vc_memh))
panic("vga_common_setup: couldn't map memory");
vc->vc_nrow = 25;
vc->vc_ncol = 80;
bus_space_write_1(iot, ioh, VGA_6845_ADDR, 14);
cpos = bus_space_read_1(iot, ioh, VGA_6845_DATA) << 8;
bus_space_write_1(iot, ioh, VGA_6845_ADDR, 15);
cpos |= bus_space_read_1(iot, ioh, VGA_6845_DATA);
bus_space_write_1(iot, vc->vc_ioh_d, VGA_IO_D_6845_ADDR, 14);
cpos = bus_space_read_1(iot, vc->vc_ioh_d, VGA_IO_D_6845_DATA) << 8;
bus_space_write_1(iot, vc->vc_ioh_d, VGA_IO_D_6845_ADDR, 15);
cpos |= bus_space_read_1(iot, vc->vc_ioh_d, VGA_IO_D_6845_DATA);
vc->vc_crow = cpos / vc->vc_ncol;
vc->vc_ccol = cpos % vc->vc_ncol;
@ -197,7 +246,7 @@ vga_cursor(id, on, row, col)
{
struct vga_config *vc = id;
bus_space_tag_t iot = vc->vc_iot;
bus_space_handle_t ioh = vc->vc_ioh;
bus_space_handle_t ioh_d = vc->vc_ioh_d;
int pos;
#if 0
@ -214,10 +263,10 @@ vga_cursor(id, on, row, col)
pos = row * vc->vc_ncol + col;
bus_space_write_1(iot, ioh, VGA_6845_ADDR, 14);
bus_space_write_1(iot, ioh, VGA_6845_DATA, pos >> 8);
bus_space_write_1(iot, ioh, VGA_6845_ADDR, 15);
bus_space_write_1(iot, ioh, VGA_6845_DATA, pos);
bus_space_write_1(iot, ioh_d, VGA_IO_D_6845_ADDR, 14);
bus_space_write_1(iot, ioh_d, VGA_IO_D_6845_DATA, pos >> 8);
bus_space_write_1(iot, ioh_d, VGA_IO_D_6845_ADDR, 15);
bus_space_write_1(iot, ioh_d, VGA_IO_D_6845_DATA, pos);
}
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: vgavar.h,v 1.1 1996/11/19 04:38:33 cgd Exp $ */
/* $NetBSD: vgavar.h,v 1.2 1996/11/23 06:06:43 cgd Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@ -32,7 +32,7 @@ struct vga_config {
* Filled in by front-ends.
*/
bus_space_tag_t vc_iot, vc_memt;
bus_space_handle_t vc_ioh, vc_memh;
bus_space_handle_t vc_ioh_b, vc_ioh_c, vc_ioh_d, vc_memh;
/*
* Private to back-end.
@ -45,6 +45,8 @@ struct vga_config {
char vc_so_at; /* standout attributes */
};
void vga_getconfig __P((struct vga_config *));
int vga_common_probe __P((bus_space_tag_t, bus_space_tag_t));
void vga_common_setup __P((bus_space_tag_t, bus_space_tag_t,
struct vga_config *));
void vga_wscons_attach __P((struct device *, struct vga_config *, int));
void vga_wscons_console __P((struct vga_config *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: vga_isa.c,v 1.2 1996/11/20 20:04:53 cgd Exp $ */
/* $NetBSD: vga_isa.c,v 1.3 1996/11/23 06:06:44 cgd Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@ -57,37 +57,6 @@ struct cfattach vga_isa_ca = {
int vga_isa_console_tag; /* really just a boolean. */
struct vga_config vga_isa_console_vc;
int
vga_isa_probe(iot, memt)
bus_space_tag_t iot, memt;
{
bus_space_handle_t ioh, memh;
u_int16_t vgadata;
int gotio, gotmem, rv;
gotio = gotmem = rv = 0;
if (bus_space_map(iot, 0x3b0, 0x30, 0, &ioh))
goto bad;
gotio = 1;
if (bus_space_map(memt, 0xb8000, 0x8000, 0, &memh))
goto bad;
gotmem = 1;
vgadata = bus_space_read_2(memt, memh, 0);
bus_space_write_2(memt, memh, 0, 0xa55a);
rv = (bus_space_read_2(memt, memh, 0) == 0xa55a);
bus_space_write_2(memt, memh, 0, vgadata);
bad:
if (gotmem)
bus_space_unmap(memt, memh, 0x8000);
if (gotio)
bus_space_unmap(iot, ioh, 0x30);
return (rv);
}
int
vga_isa_match(parent, match, aux)
struct device *parent;
@ -97,8 +66,7 @@ vga_isa_match(parent, match, aux)
int rv;
/* If values are hardwired to something that they can't be, punt. */
if ((ia->ia_iobase != IOBASEUNK && ia->ia_iobase != 0x3b0) ||
/* (ia->ia_iosize != 0 && ia->ia_iosize != 0x30) || XXX isa.c */
if (ia->ia_iobase != IOBASEUNK || /* ia->ia_iosize != 0 || XXX isa.c */
(ia->ia_maddr != MADDRUNK && ia->ia_maddr != 0xb8000) ||
(ia->ia_msize != 0 && ia->ia_msize != 0x8000) ||
ia->ia_irq != IRQUNK || ia->ia_drq != DRQUNK)
@ -107,7 +75,7 @@ vga_isa_match(parent, match, aux)
if (vga_isa_console_tag)
return (1);
rv = vga_isa_probe(ia->ia_iot, ia->ia_memt);
rv = vga_common_probe(ia->ia_iot, ia->ia_memt);
if (rv) {
ia->ia_iobase = 0x3b0;
@ -135,15 +103,8 @@ vga_isa_attach(parent, self, aux)
vc = sc->sc_vc = (struct vga_config *)
malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK);
/* for bus-independent VGA code */
vc->vc_iot = ia->ia_iot;
vc->vc_memt = ia->ia_memt;
if (bus_space_map(vc->vc_iot, 0x3b0, 0x30, 0, &vc->vc_ioh))
panic("vga_isa_attach: couldn't map io");
if (bus_space_map(vc->vc_memt, 0xb8000, 0x8000, 0,
&vc->vc_memh))
panic("vga_isa_attach: couldn't map memory");
vga_getconfig(vc);
/* set up bus-independent VGA configuration */
vga_common_setup(ia->ia_iot, ia->ia_memt, vc);
}
printf("\n");
@ -151,8 +112,16 @@ vga_isa_attach(parent, self, aux)
vga_wscons_attach(self, vc, console);
}
int
vga_isa_console_match(iot, memt)
bus_space_tag_t iot, memt;
{
return (vga_common_probe(iot, memt));
}
void
vga_isa_console(iot, memt)
vga_isa_console_attach(iot, memt)
bus_space_tag_t iot, memt;
{
struct vga_config *vc = &vga_isa_console_vc;
@ -160,14 +129,8 @@ vga_isa_console(iot, memt)
/* for later recognition */
vga_isa_console_tag = 1;
/* for bus-independent VGA code */
vc->vc_iot = iot;
vc->vc_memt = memt;
if (bus_space_map(vc->vc_iot, 0x3b0, 0x30, 0, &vc->vc_ioh))
panic("vga_isa_console: couldn't map io");
if (bus_space_map(vc->vc_memt, 0xb8000, 0x8000, 0, &vc->vc_memh))
panic("vga_isa_console: couldn't map memory");
vga_getconfig(vc);
/* set up bus-independent VGA configuration */
vga_common_setup(iot, memt, vc);
vga_wscons_console(vc);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vga_isavar.h,v 1.1 1996/11/19 04:38:34 cgd Exp $ */
/* $NetBSD: vga_isavar.h,v 1.2 1996/11/23 06:06:45 cgd Exp $ */
/*
* Copyright (c) 1996 Carnegie-Mellon University.
@ -27,5 +27,5 @@
* rights to redistribute these changes.
*/
int vga_isa_probe __P((bus_space_tag_t, bus_space_tag_t));
void vga_isa_console __P((bus_space_tag_t, bus_space_tag_t));
int vga_isa_console_match __P((bus_space_tag_t, bus_space_tag_t));
void vga_isa_console_attach __P((bus_space_tag_t, bus_space_tag_t));

View File

@ -1,4 +1,4 @@
/* $NetBSD: vga_pci.c,v 1.1 1996/11/19 04:38:35 cgd Exp $ */
/* $NetBSD: vga_pci.c,v 1.2 1996/11/23 06:06:47 cgd Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@ -66,18 +66,27 @@ vga_pci_match(parent, match, aux)
void *match, *aux;
{
struct pci_attach_args *pa = aux;
int potential;
potential = 0;
/*
* If it's prehistoric/vga or display/vga, we match.
* If it's prehistoric/vga or display/vga, we might match.
*/
if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PREHISTORIC &&
PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PREHISTORIC_VGA)
return (1);
potential = 1;
if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY &&
PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_DISPLAY_VGA)
return (1);
potential = 1;
return (0);
/*
* If we might match, make sure that the card actually looks OK.
*/
if (potential && vga_common_probe(pa->pa_iot, pa->pa_memt) == 0)
potential = 0;
return (potential);
}
void
@ -98,15 +107,8 @@ vga_pci_attach(parent, self, aux)
vc = sc->sc_vc = (struct vga_config *)
malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK);
/* for bus-independent VGA code */
vc->vc_iot = pa->pa_iot;
vc->vc_memt = pa->pa_memt;
if (bus_space_map(vc->vc_iot, 0x3b0, 0x30, 0, &vc->vc_ioh))
panic("vga_pci_attach: couldn't map io");
if (bus_space_map(vc->vc_memt, 0xb8000, 0x8000, 0,
&vc->vc_memh))
panic("vga_pci_attach: couldn't map memory");
vga_getconfig(vc);
/* set up bus-independent VGA configuration */
vga_common_setup(pa->pa_iot, pa->pa_memt, vc);
}
sc->sc_pcitag = pa->pa_tag;
@ -129,14 +131,8 @@ vga_pci_console(iot, memt, pc, bus, device, function)
/* for later recognition */
vga_pci_console_tag = pci_make_tag(pc, bus, device, function);
/* for bus-independent VGA code */
vc->vc_iot = iot;
vc->vc_memt = memt;
if (bus_space_map(vc->vc_iot, 0x3b0, 0x30, 0, &vc->vc_ioh))
panic("vga_pci_console: couldn't map io");
if (bus_space_map(vc->vc_memt, 0xb8000, 0x8000, 0, &vc->vc_memh))
panic("vga_pci_console: couldn't map memory");
vga_getconfig(vc);
/* set up bus-independent VGA configuration */
vga_common_setup(iot, memt, vc);
vga_wscons_console(vc);
}