diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2012-08-30 21:54:14 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2012-08-30 21:54:14 +0000 |
commit | 0821942a0d05ebe8d6d61961cc288b4aa74b5a11 (patch) | |
tree | d209841ddaa6f2b45782cfc7370096c34d071fb8 /sys/arch/macppc | |
parent | a1ba67441d331d770cf5401df582e7c294c53539 (diff) |
Determine the memory and mmio regions based on previously initialzed BAR
structures and add the necessary glue to attach drm(4).
ok kettenis@
Diffstat (limited to 'sys/arch/macppc')
-rw-r--r-- | sys/arch/macppc/conf/files.macppc | 4 | ||||
-rw-r--r-- | sys/arch/macppc/macppc/conf.c | 6 | ||||
-rw-r--r-- | sys/arch/macppc/pci/vgafb.c | 36 | ||||
-rw-r--r-- | sys/arch/macppc/pci/vgafb_pci.c | 219 | ||||
-rw-r--r-- | sys/arch/macppc/pci/vgafbvar.h | 13 |
5 files changed, 104 insertions, 174 deletions
diff --git a/sys/arch/macppc/conf/files.macppc b/sys/arch/macppc/conf/files.macppc index 60b69d7fc6b..ab0b9bcdaf3 100644 --- a/sys/arch/macppc/conf/files.macppc +++ b/sys/arch/macppc/conf/files.macppc @@ -1,4 +1,4 @@ -# $OpenBSD: files.macppc,v 1.65 2011/11/15 22:27:53 deraadt Exp $ +# $OpenBSD: files.macppc,v 1.66 2012/08/30 21:54:13 mpi Exp $ # # macppc-specific configuration info @@ -250,7 +250,7 @@ include "dev/rasops/files.rasops" include "dev/wsfont/files.wsfont" # VGA framebuffer -device vgafb: wsemuldisplaydev, rasops8, rasops16, rasops32 +device vgafb: wsemuldisplaydev, rasops8, rasops16, rasops32, drmdev file arch/macppc/pci/vgafb.c vgafb & vgafb_pci # Generic VGA Framebuffer version diff --git a/sys/arch/macppc/macppc/conf.c b/sys/arch/macppc/macppc/conf.c index ab374da1593..81e32d33345 100644 --- a/sys/arch/macppc/macppc/conf.c +++ b/sys/arch/macppc/macppc/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.48 2012/08/23 06:12:49 deraadt Exp $ */ +/* $OpenBSD: conf.c,v 1.49 2012/08/30 21:54:13 mpi Exp $ */ /* * Copyright (c) 1997 Per Fogelstrom @@ -114,6 +114,8 @@ cdev_decl(com); #include "apm.h" #include "bthub.h" +#include "drm.h" +cdev_decl(drm); #include "wsmux.h" @@ -234,6 +236,8 @@ struct cdevsw cdevsw[] = { cdev_vscsi_init(NVSCSI,vscsi), /* 83: vscsi */ cdev_disk_init(1,diskmap), /* 84: disk mapper */ cdev_pppx_init(NPPPX,pppx), /* 85: pppx */ + cdev_notdef(), /* 86: agp */ + cdev_drm_init(NDRM,drm), /* 87: drm */ }; int nchrdev = nitems(cdevsw); diff --git a/sys/arch/macppc/pci/vgafb.c b/sys/arch/macppc/pci/vgafb.c index 023e8181f32..281c291e274 100644 --- a/sys/arch/macppc/pci/vgafb.c +++ b/sys/arch/macppc/pci/vgafb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vgafb.c,v 1.40 2012/06/21 10:08:16 mpi Exp $ */ +/* $OpenBSD: vgafb.c,v 1.41 2012/08/30 21:54:13 mpi Exp $ */ /* $NetBSD: vga.c,v 1.3 1996/12/02 22:24:54 cgd Exp $ */ /* @@ -53,16 +53,16 @@ struct cfdriver vgafb_cd = { NULL, "vgafb", DV_DULL, }; -void vgafb_setcolor(struct vgafb_config *vc, unsigned int index, +void vgafb_setcolor(struct vga_config *vc, unsigned int index, u_int8_t r, u_int8_t g, u_int8_t b); -void vgafb_restore_default_colors(struct vgafb_config *vc); +void vgafb_restore_default_colors(struct vga_config *vc); struct vgafb_devconfig { struct rasops_info dc_rinfo; /* raster display data */ int dc_blanked; /* currently had video disabled */ }; -extern struct vgafb_config vgafb_pci_console_vc; +extern struct vga_config vgafb_pci_console_vc; struct vgafb_devconfig vgafb_console_dc; struct wsscreen_descr vgafb_stdscreen = { @@ -94,8 +94,8 @@ struct wsdisplay_accessops vgafb_accessops = { vgafb_burn, /* burner */ }; -int vgafb_getcmap(struct vgafb_config *vc, struct wsdisplay_cmap *cm); -int vgafb_putcmap(struct vgafb_config *vc, struct wsdisplay_cmap *cm); +int vgafb_getcmap(struct vga_config *vc, struct wsdisplay_cmap *cm); +int vgafb_putcmap(struct vga_config *vc, struct wsdisplay_cmap *cm); #define FONT_WIDTH 8 #define FONT_HEIGHT 16 @@ -106,7 +106,7 @@ extern int allowaperture; void -vgafb_init(bus_space_tag_t iot, bus_space_tag_t memt, struct vgafb_config *vc, +vgafb_init(bus_space_tag_t iot, bus_space_tag_t memt, struct vga_config *vc, u_int32_t membase, size_t memsize, u_int32_t mmiobase, size_t mmiosize) { vc->vc_iot = iot; @@ -140,7 +140,7 @@ vgafb_init(bus_space_tag_t iot, bus_space_tag_t memt, struct vgafb_config *vc, } void -vgafb_restore_default_colors(struct vgafb_config *vc) +vgafb_restore_default_colors(struct vga_config *vc) { int i; @@ -153,7 +153,7 @@ vgafb_restore_default_colors(struct vgafb_config *vc) } void -vgafb_wsdisplay_attach(struct device *parent, struct vgafb_config *vc, +vgafb_wsdisplay_attach(struct device *parent, struct vga_config *vc, int console) { struct wsemuldisplaydev_attach_args aa; @@ -178,7 +178,7 @@ vgafb_wsdisplay_attach(struct device *parent, struct vgafb_config *vc, int vgafb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p) { - struct vgafb_config *vc = v; + struct vga_config *vc = v; struct wsdisplay_fbinfo *wdf; switch (cmd) { @@ -282,7 +282,7 @@ vgafb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p) paddr_t vgafb_mmap(void *v, off_t off, int prot) { - struct vgafb_config *vc = v; + struct vga_config *vc = v; if (off & PGOFSET) return (-1); @@ -317,7 +317,7 @@ vgafb_mmap(void *v, off_t off, int prot) int vgafb_cnattach(bus_space_tag_t iot, bus_space_tag_t memt, int type, int check) { - struct vgafb_config *vc = &vgafb_pci_console_vc; + struct vga_config *vc = &vgafb_pci_console_vc; struct vgafb_devconfig *dc = &vgafb_console_dc; struct rasops_info *ri = &dc->dc_rinfo; long defattr; @@ -358,7 +358,7 @@ struct { } vgafb_color[256]; void -vgafb_setcolor(struct vgafb_config *vc, unsigned int index, u_int8_t r, +vgafb_setcolor(struct vga_config *vc, unsigned int index, u_int8_t r, u_int8_t g, u_int8_t b) { vc->vc_cmap_red[index] = r; @@ -373,7 +373,7 @@ vgafb_setcolor(struct vgafb_config *vc, unsigned int index, u_int8_t r, } int -vgafb_getcmap(struct vgafb_config *vc, struct wsdisplay_cmap *cm) +vgafb_getcmap(struct vga_config *vc, struct wsdisplay_cmap *cm) { u_int index = cm->index; u_int count = cm->count; @@ -396,7 +396,7 @@ vgafb_getcmap(struct vgafb_config *vc, struct wsdisplay_cmap *cm) } int -vgafb_putcmap(struct vgafb_config *vc, struct wsdisplay_cmap *cm) +vgafb_putcmap(struct vga_config *vc, struct wsdisplay_cmap *cm) { u_int index = cm->index; u_int count = cm->count; @@ -432,7 +432,7 @@ vgafb_putcmap(struct vgafb_config *vc, struct wsdisplay_cmap *cm) void vgafb_burn(void *v, u_int on, u_int flags) { - struct vgafb_config *vc = v; + struct vga_config *vc = v; if (cons_backlight_available == 1 && vc->vc_backlight_on != on) { @@ -449,7 +449,7 @@ int vgafb_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep, int *curxp, int *curyp, long *attrp) { - struct vgafb_config *vc = v; + struct vga_config *vc = v; long defattr; if (vc->nscreens > 0) @@ -469,7 +469,7 @@ vgafb_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep, void vgafb_free_screen(void *v, void *cookie) { - struct vgafb_config *vc = v; + struct vga_config *vc = v; if (vc == &vgafb_pci_console_vc) panic("vgafb_free_screen: console"); diff --git a/sys/arch/macppc/pci/vgafb_pci.c b/sys/arch/macppc/pci/vgafb_pci.c index 8e8bc529a14..681413f85a6 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.25 2012/06/21 10:08:16 mpi Exp $ */ +/* $OpenBSD: vgafb_pci.c,v 1.26 2012/08/30 21:54:13 mpi Exp $ */ /* $NetBSD: vga_pci.c,v 1.4 1996/12/05 01:39:38 cgd Exp $ */ /* @@ -47,175 +47,99 @@ #include <dev/rasops/rasops.h> #include <dev/wsfont/wsfont.h> -#include <arch/macppc/pci/vgafbvar.h> -#include <arch/macppc/pci/vgafb_pcivar.h> +#include "drm.h" -#define PCI_VENDORID(x) ((x) & 0xFFFF) -#define PCI_CHIPID(x) (((x) >> 16) & 0xFFFF) +#include <arch/macppc/pci/vgafbvar.h> +#include <dev/pci/vga_pcivar.h> -struct vgafb_pci_softc { - struct device sc_dev; - - pcitag_t sc_pcitag; /* PCI tag, in case we need it. */ - struct vgafb_config *sc_vc; /* VGA configuration */ -}; +#ifdef DEBUG_VGAFB +#define DPRINTF(x...) do { printf(x); } while (0); +#else +#define DPRINTF(x...) +#endif -int vgafb_pci_probe(struct pci_attach_args *pa, int id, u_int32_t *ioaddr, - u_int32_t *iosize, u_int32_t *memaddr, u_int32_t *memsize, - u_int32_t *cacheable, u_int32_t *mmioaddr, u_int32_t *mmiosize); int vgafb_pci_match(struct device *, void *, void *); void vgafb_pci_attach(struct device *, struct device *, void *); +void vgafb_pci_mem_init(struct vga_pci_softc *, uint32_t *, uint32_t *, + uint32_t *, uint32_t *); + struct cfattach vgafb_pci_ca = { - sizeof(struct vgafb_pci_softc), (cfmatch_t)vgafb_pci_match, vgafb_pci_attach, + sizeof(struct vga_pci_softc), (cfmatch_t)vgafb_pci_match, vgafb_pci_attach, }; pcitag_t vgafb_pci_console_tag; -struct vgafb_config vgafb_pci_console_vc; - -#if 0 -#define DEBUG_VGAFB -#endif +struct vga_config vgafb_pci_console_vc; -int -vgafb_pci_probe(struct pci_attach_args *pa, int id, u_int32_t *ioaddr, - u_int32_t *iosize, u_int32_t *memaddr, u_int32_t *memsize, - u_int32_t *cacheable, u_int32_t *mmioaddr, u_int32_t *mmiosize) +void +vgafb_pci_mem_init(struct vga_pci_softc *dev, uint32_t *memaddr, + uint32_t *memsize, uint32_t *mmioaddr, uint32_t *mmiosize) { - bus_addr_t addr; - bus_size_t size; - int tcacheable; - pci_chipset_tag_t pc = pa->pa_pc; - int retval; + struct vga_pci_bar *bar; int i; - *iosize = 0x0; *memsize = 0x0; *mmiosize = 0x0; - for (i = PCI_MAPREG_START; i <= PCI_MAPREG_PPB_END; i += 4) { -#ifdef DEBUG_VGAFB - printf("vgafb confread %x %x\n", - i, pci_conf_read(pc, pa->pa_tag, i)); -#endif - /* need to check more than just two base addresses? */ - if (PCI_MAPREG_TYPE(pci_conf_read(pc, pa->pa_tag, i)) == - PCI_MAPREG_TYPE_IO) { - retval = pci_io_find(pc, pa->pa_tag, i, - &addr, &size); - if (retval != 0) { - continue; - } -#ifdef DEBUG_VGAFB - printf("vgafb_pci_probe: io %x addr %x size %x\n", i, addr, size); -#endif - if (*iosize == 0) { - *ioaddr = addr; - *iosize = size; - } - } else { - retval = pci_mem_find(pc, pa->pa_tag, i, - &addr, &size, &tcacheable); - if (retval != 0) { - continue; - } -#ifdef DEBUG_VGAFB - printf("vgafb_pci_probe: mem %x addr %x size %x\n", i, addr, size); -#endif - if (size == 0 || addr == 0) { + for (i = 0; i < VGA_PCI_MAX_BARS; i++) { + bar = dev->bars[i]; + if (bar == NULL) + continue; + + DPRINTF("\nvgafb: 0x%04x: BAR ", bar->addr); + + switch (PCI_MAPREG_TYPE(bar->maptype)) { + case PCI_MAPREG_TYPE_IO: + DPRINTF("io "); + break; + case PCI_MAPREG_TYPE_MEM: + if (bar->base == 0 || bar->maxsize == 0) { /* ignore this entry */ } else if (*memsize == 0) { /* * first memory slot found goes into memory, * this is for the case of no mmio */ - *memaddr = addr; - *memsize = size; - *cacheable = tcacheable; + *memaddr = bar->base; + *memsize = bar->maxsize; } else { /* - * Oh, we have a second 'memory' + * Oh, we have a second 'memory' * region, is this region the vga memory * or mmio, we guess that memory is * the larger of the two. - */ - if (*memaddr >= size) { + */ + if (*memsize >= bar->maxsize) { /* this is the mmio */ - *mmioaddr = addr; - /* ATI driver maps 0x80000 mmio, grr */ - if (size < 0x80000) { - size = 0x80000; - } - *mmiosize = size; + *mmioaddr = bar->base; + *mmiosize = bar->maxsize; } else { /* this is the memory */ *mmioaddr = *memaddr; - *memaddr = addr; *mmiosize = *memsize; - *memsize = size; - *cacheable = tcacheable; - /* ATI driver maps 0x80000 mmio, grr */ - if (*mmiosize < 0x80000) { - *mmiosize = 0x80000; - } + *memaddr = bar->base; + *memsize = bar->maxsize; } } + DPRINTF("mem "); + break; } - } -#ifdef DEBUG_VGAFB - printf("vgafb_pci_probe: id %x ioaddr %x, iosize %x, memaddr %x,\n memsize %x, mmioaddr %x, mmiosize %x\n", - id, *ioaddr, *iosize, *memaddr, *memsize, *mmioaddr, *mmiosize); -#endif - if (*iosize == 0) { - if (id == 0) { -#ifdef powerpc - /* this is only used if on openfirmware system and - * the device does not have a iobase config register, - * eg CirrusLogic 5434 VGA. (they hardcode iobase to 0 - * thus giving standard PC addresses for the registers) - */ - int s; - u_int32_t sizedata; - - /* - * Open Firmware (yuck) shuts down devices before - * entering a program so we need to bring them back - * 'online' to respond to bus accesses... so far - * this is true on the power.4e. - */ - s = splhigh(); - sizedata = pci_conf_read(pc, pa->pa_tag, - PCI_COMMAND_STATUS_REG); - sizedata |= (PCI_COMMAND_MASTER_ENABLE | - PCI_COMMAND_IO_ENABLE | - PCI_COMMAND_PARITY_ENABLE | - PCI_COMMAND_SERR_ENABLE); - pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, - sizedata); - splx(s); -#endif - /* if this is the first card, allow it - * to be accessed in vga iospace - */ - *ioaddr = 0; - *iosize = 0x10000; /* 64k, good as any */ + if (bar->maptype == PCI_MAPREG_MEM_TYPE_64BIT) { + DPRINTF("64bit"); + i++; } else { - /* iospace not available, assume 640x480, pray */ - *ioaddr = 0; - *iosize = 0; + DPRINTF("addr: 0x%08x/0x%08x", bar->base, bar->maxsize); } } -#ifdef DEBUG_VGAFB - printf("vgafb_pci_probe: id %x ioaddr %x, iosize %x, memaddr %x,\n memsize %x, mmioaddr %x, mmiosize %x\n", - id, *ioaddr, *iosize, *memaddr, *memsize, *mmioaddr, *mmiosize); -#endif - - /* io and mmio spaces are not required to attach */ - if (/* *iosize == 0 || */ *memsize == 0 /* || *mmiosize == 0 */) - return (0); - return (1); + /* ATI driver maps 0x80000 mmio, grr */ + if (*mmiosize > 0 && *mmiosize < 0x80000) { + *mmiosize = 0x80000; + } + + DPRINTF("\nvgafb: memaddr %x, memsize %x, mmioaddr %x, mmiosize %x", + *memaddr, *memsize, *mmioaddr, *mmiosize); } int @@ -249,32 +173,37 @@ void vgafb_pci_attach(struct device *parent, struct device *self, void *aux) { struct pci_attach_args *pa = aux; - struct vgafb_pci_softc *sc = (struct vgafb_pci_softc *)self; - struct vgafb_config *vc; - u_int32_t memaddr, memsize, cacheable; - u_int32_t ioaddr, iosize; + struct vga_pci_softc *sc = (struct vga_pci_softc *)self; + struct vga_config *vc; + u_int32_t memaddr, memsize; u_int32_t mmioaddr, mmiosize; int console; - static int id = 0; - int myid; + pcireg_t reg; - myid = id; - vgafb_pci_probe(pa, myid, &ioaddr, &iosize, - &memaddr, &memsize, &cacheable, &mmioaddr, &mmiosize); + vga_pci_bar_init(sc, pa); + vgafb_pci_mem_init(sc, &memaddr, &memsize, &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; else { - vc = sc->sc_vc = (struct vgafb_config *) - malloc(sizeof(struct vgafb_config), M_DEVBUF, M_WAITOK); + vc = sc->sc_vc = (struct vga_config *) + malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK); /* set up bus-independent VGA configuration */ vgafb_init(pa->pa_iot, pa->pa_memt, vc, memaddr, memsize, mmioaddr, mmiosize); } + + /* + * Enable bus master; X might need this for accelerated graphics. + */ + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); + reg |= PCI_COMMAND_MASTER_ENABLE; + pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, reg); + vc->vc_mmap = vgafb_mmap; vc->vc_ioctl = vgafb_ioctl; vc->membase = memaddr; @@ -282,16 +211,14 @@ vgafb_pci_attach(struct device *parent, struct device *self, void *aux) vc->mmiobase = mmioaddr; vc->mmiosize = mmiosize; - sc->sc_pcitag = pa->pa_tag; - - if (iosize == 0) - printf (", no io"); - if (mmiosize != 0) printf (", mmio"); printf("\n"); vgafb_wsdisplay_attach(self, vc, console); - id++; + +#if NDRM > 0 + config_found_sm(self, aux, NULL, drmsubmatch); +#endif } diff --git a/sys/arch/macppc/pci/vgafbvar.h b/sys/arch/macppc/pci/vgafbvar.h index 2708a732f7f..46786208ddf 100644 --- a/sys/arch/macppc/pci/vgafbvar.h +++ b/sys/arch/macppc/pci/vgafbvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vgafbvar.h,v 1.14 2012/06/21 10:08:16 mpi Exp $ */ +/* $OpenBSD: vgafbvar.h,v 1.15 2012/08/30 21:54:13 mpi Exp $ */ /* $NetBSD: vgavar.h,v 1.2 1996/11/23 06:06:43 cgd Exp $ */ /* @@ -28,7 +28,7 @@ * rights to redistribute these changes. */ -struct vgafb_config { +struct vga_config { /* * Filled in by front-ends. */ @@ -68,12 +68,11 @@ struct vgafb_config { }; void vgafb_init(bus_space_tag_t, bus_space_tag_t, - struct vgafb_config *, u_int32_t, size_t, u_int32_t, size_t); -void vgafb_wscons_attach(struct device *, struct vgafb_config *, int); -void vgafb_wscons_console(struct vgafb_config *); + struct vga_config *, u_int32_t, size_t, u_int32_t, size_t); +void vgafb_wscons_attach(struct device *, struct vga_config *, int); +void vgafb_wscons_console(struct vga_config *); int vgafb_cnattach(bus_space_tag_t, bus_space_tag_t, int, int); -void vgafb_wsdisplay_attach(struct device *parent, - struct vgafb_config *vc, int console); +void vgafb_wsdisplay_attach(struct device *, struct vga_config *, int); int vgafbioctl(void *, u_long, caddr_t, int, struct proc *); paddr_t vgafbmmap(void *, off_t, int); int vgafb_ioctl(void *, u_long, caddr_t, int, struct proc *); |