summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2002-03-26 16:51:44 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2002-03-26 16:51:44 +0000
commitf6989103fe456a7384cf113d99a620ac97bad79c (patch)
tree28460d8ebab1c6b6de320ead010cc55eb02b54d7 /sys/arch
parent98f6aab0a210e093d82725405a0106e5f2fb129c (diff)
Only allow valid device PAs to be mmapped.
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/macppc/pci/vgafb.c22
-rw-r--r--sys/arch/macppc/pci/vgafb_pci.c17
-rw-r--r--sys/arch/macppc/pci/vgafbvar.h11
3 files changed, 34 insertions, 16 deletions
diff --git a/sys/arch/macppc/pci/vgafb.c b/sys/arch/macppc/pci/vgafb.c
index e97cddf3385..7878c680121 100644
--- a/sys/arch/macppc/pci/vgafb.c
+++ b/sys/arch/macppc/pci/vgafb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vgafb.c,v 1.6 2002/03/14 01:26:37 millert Exp $ */
+/* $OpenBSD: vgafb.c,v 1.7 2002/03/26 16:51:43 drahn Exp $ */
/* $NetBSD: vga.c,v 1.3 1996/12/02 22:24:54 cgd Exp $ */
/*
@@ -381,7 +381,7 @@ vgafb_mmap(v, offset, prot)
bus_space_handle_t h;
/* memsize... */
- if (offset >= 0x00000 && offset < 0x800000) /* 8MB of mem??? */
+ if (offset >= 0x00000 && offset < vc->memsize)
h = vc->vc_paddr + offset;
/* XXX the following are probably wrong. we want physical addresses
here, not virtual ones */
@@ -394,18 +394,18 @@ vgafb_mmap(v, offset, prot)
else if (offset >= 0x18880000 && offset < 0x100c0000)
/* 256KB of iohd */
h = vc->vc_ioh_d;
- else if (offset >= 0x20000000 && offset < 0x30000000)
+ else if (offset >= 0x20000000 && offset < 0x20000000+vc->mmiosize)
/* mmiosize... */
h = vc->vc_mmioh + (offset - 0x20000000);
- else {
- /* XXX - allow mapping of the actual physical
- * device address, if the address is read from
- * pci bus config space
- */
-
- /* NEEDS TO BE RESTRICTED to valid addresses for this device */
-
+ else if (offset >= vc->membase && (offset < vc->membase+vc->memsize)) {
+ /* allow mmapping of memory */
h = offset;
+ } else if (offset >= vc->mmiobase &&
+ (offset < vc->mmiobase+vc->mmiosize)) {
+ /* allow mmapping of mmio space */
+ h = offset;
+ } else {
+ h = -1;
}
#ifdef alpha
diff --git a/sys/arch/macppc/pci/vgafb_pci.c b/sys/arch/macppc/pci/vgafb_pci.c
index 0b98fe61c56..352e8332fab 100644
--- a/sys/arch/macppc/pci/vgafb_pci.c
+++ b/sys/arch/macppc/pci/vgafb_pci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vgafb_pci.c,v 1.3 2002/03/14 01:26:37 millert Exp $ */
+/* $OpenBSD: vgafb_pci.c,v 1.4 2002/03/26 16:51:43 drahn Exp $ */
/* $NetBSD: vga_pci.c,v 1.4 1996/12/05 01:39:38 cgd Exp $ */
/*
@@ -104,7 +104,7 @@ vgafb_pci_probe(pa, id, ioaddr, iosize, memaddr, memsize, cacheable, mmioaddr, m
*iosize = 0x0;
*memsize = 0x0;
*mmiosize = 0x0;
- for (i = 0x10; i < 0x18; i += 4) {
+ for (i = 0x10; i <= 0x18; i += 4) {
#ifdef DEBUG_VGAFB
printf("vgafb confread %x %x\n",
i, pci_conf_read(pc, pa->pa_tag, i));
@@ -135,7 +135,7 @@ vgafb_pci_probe(pa, id, ioaddr, iosize, memaddr, memsize, cacheable, mmioaddr, m
}
if (size == 0) {
/* ignore this entry */
- }else if (size <= (64 * 1024)) {
+ }else if (size <= (1024 * 1024)) {
#ifdef DEBUG_VGAFB
printf("vgafb_pci_probe: mem %x addr %x size %x iosize %x\n",
i, addr, size, *iosize);
@@ -143,6 +143,10 @@ vgafb_pci_probe(pa, id, ioaddr, iosize, memaddr, memsize, cacheable, mmioaddr, m
if (*mmiosize == 0) {
/* this is mmio, not memory */
*mmioaddr = addr;
+ if (size < 0x80000) {
+ /* ATI driver maps 0x80000, grr */
+ size = 0x80000;
+ }
*mmiosize = size;
/* need skew in here for io memspace */
}
@@ -305,6 +309,7 @@ vgafb_pci_attach(parent, self, aux)
vgafb_pci_probe(pa, myid, &ioaddr, &iosize,
&memaddr, &memsize, &cacheable, &mmioaddr, &mmiosize);
+
console = (!bcmp(&pa->pa_tag, &vgafb_pci_console_tag, sizeof(pa->pa_tag)));
if (console)
vc = sc->sc_vc = &vgafb_pci_console_vc;
@@ -318,6 +323,12 @@ vgafb_pci_attach(parent, self, aux)
}
vc->vc_mmap = vgafbpcimmap;
vc->vc_ioctl = vgafbpciioctl;
+ vc->iobase = ioaddr;
+ vc->iosize = iosize;
+ vc->membase = memaddr;
+ vc->memsize = memsize;
+ vc->mmiobase = mmioaddr;
+ vc->mmiosize = mmiosize;
sc->sc_pcitag = pa->pa_tag;
diff --git a/sys/arch/macppc/pci/vgafbvar.h b/sys/arch/macppc/pci/vgafbvar.h
index 79e5042655f..58ca2de2305 100644
--- a/sys/arch/macppc/pci/vgafbvar.h
+++ b/sys/arch/macppc/pci/vgafbvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: vgafbvar.h,v 1.4 2002/03/14 03:15:56 millert Exp $ */
+/* $OpenBSD: vgafbvar.h,v 1.5 2002/03/26 16:51:43 drahn Exp $ */
/* $NetBSD: vgavar.h,v 1.2 1996/11/23 06:06:43 cgd Exp $ */
/*
@@ -59,7 +59,14 @@ struct vgafb_config {
#endif
struct rcons dc_rcons; /* raster blitter control info */
-
+ bus_addr_t iobase;
+ bus_size_t iosize;
+
+ bus_addr_t membase;
+ bus_size_t memsize;
+
+ bus_addr_t mmiobase;
+ bus_size_t mmiosize;
};
int vgafb_common_probe(bus_space_tag_t, bus_space_tag_t,