1 1.31 drochner /* $NetBSD: chipsfb.c,v 1.31 2012/01/30 19:41:18 drochner Exp $ */ 2 1.1 macallan 3 1.1 macallan /* 4 1.1 macallan * Copyright (c) 2006 Michael Lorenz 5 1.1 macallan * All rights reserved. 6 1.1 macallan * 7 1.1 macallan * Redistribution and use in source and binary forms, with or without 8 1.1 macallan * modification, are permitted provided that the following conditions 9 1.1 macallan * are met: 10 1.1 macallan * 1. Redistributions of source code must retain the above copyright 11 1.1 macallan * notice, this list of conditions and the following disclaimer. 12 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 macallan * notice, this list of conditions and the following disclaimer in the 14 1.1 macallan * documentation and/or other materials provided with the distribution. 15 1.1 macallan * 16 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 1.1 macallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 1.1 macallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 1.1 macallan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 1.1 macallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 1.1 macallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 1.1 macallan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 1.1 macallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 1.1 macallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 1.1 macallan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 1.1 macallan */ 27 1.1 macallan 28 1.8 macallan /* 29 1.1 macallan * A console driver for Chips & Technologies 65550 graphics controllers 30 1.8 macallan * tested on macppc only so far 31 1.1 macallan */ 32 1.1 macallan 33 1.1 macallan #include <sys/cdefs.h> 34 1.31 drochner __KERNEL_RCSID(0, "$NetBSD: chipsfb.c,v 1.31 2012/01/30 19:41:18 drochner Exp $"); 35 1.1 macallan 36 1.1 macallan #include <sys/param.h> 37 1.1 macallan #include <sys/systm.h> 38 1.1 macallan #include <sys/kernel.h> 39 1.1 macallan #include <sys/device.h> 40 1.1 macallan #include <sys/kauth.h> 41 1.1 macallan 42 1.1 macallan #include <dev/pci/pcivar.h> 43 1.1 macallan #include <dev/pci/pcireg.h> 44 1.1 macallan #include <dev/pci/pcidevs.h> 45 1.1 macallan #include <dev/pci/pciio.h> 46 1.26 macallan #include <dev/pci/wsdisplay_pci.h> 47 1.1 macallan 48 1.1 macallan 49 1.26 macallan #include <dev/ic/ct65550reg.h> 50 1.26 macallan #include <dev/ic/ct65550var.h> 51 1.1 macallan 52 1.1 macallan #include "opt_wsemul.h" 53 1.8 macallan #include "opt_chipsfb.h" 54 1.1 macallan 55 1.26 macallan struct chipsfb_pci_softc { 56 1.26 macallan struct chipsfb_softc sc_chips; 57 1.1 macallan pci_chipset_tag_t sc_pc; 58 1.1 macallan pcitag_t sc_pcitag; 59 1.1 macallan }; 60 1.1 macallan 61 1.26 macallan static int chipsfb_pci_match(device_t, cfdata_t, void *); 62 1.26 macallan static void chipsfb_pci_attach(device_t, device_t, void *); 63 1.26 macallan static int chipsfb_pci_ioctl(void *, void *, u_long, void *, int, 64 1.1 macallan struct lwp *); 65 1.1 macallan 66 1.26 macallan CFATTACH_DECL_NEW(chipsfb_pci, sizeof(struct chipsfb_pci_softc), 67 1.26 macallan chipsfb_pci_match, chipsfb_pci_attach, NULL, NULL); 68 1.1 macallan 69 1.1 macallan static int 70 1.26 macallan chipsfb_pci_match(device_t parent, cfdata_t match, void *aux) 71 1.1 macallan { 72 1.29 dyoung const struct pci_attach_args *pa = (const struct pci_attach_args *)aux; 73 1.1 macallan 74 1.1 macallan if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY || 75 1.1 macallan PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA) 76 1.1 macallan return 0; 77 1.8 macallan if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CHIPS) && 78 1.1 macallan (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CHIPS_65550)) 79 1.1 macallan return 100; 80 1.8 macallan if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CHIPS) && 81 1.8 macallan (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CHIPS_65554)) 82 1.8 macallan return 100; 83 1.1 macallan return 0; 84 1.1 macallan } 85 1.1 macallan 86 1.1 macallan static void 87 1.26 macallan chipsfb_pci_attach(device_t parent, device_t self, void *aux) 88 1.1 macallan { 89 1.26 macallan struct chipsfb_pci_softc *scp = device_private(self); 90 1.26 macallan struct chipsfb_softc *sc = &scp->sc_chips; 91 1.29 dyoung const struct pci_attach_args *pa = aux; 92 1.1 macallan pcireg_t screg; 93 1.1 macallan 94 1.26 macallan scp->sc_pc = pa->pa_pc; 95 1.26 macallan scp->sc_pcitag = pa->pa_tag; 96 1.26 macallan sc->sc_dev = self; 97 1.26 macallan 98 1.26 macallan screg = pci_conf_read(scp->sc_pc, scp->sc_pcitag, 99 1.26 macallan PCI_COMMAND_STATUS_REG); 100 1.28 dyoung screg |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE; 101 1.27 macallan pci_conf_write(scp->sc_pc, scp->sc_pcitag, PCI_COMMAND_STATUS_REG, 102 1.27 macallan screg); 103 1.8 macallan 104 1.31 drochner pci_aprint_devinfo(pa, NULL); 105 1.1 macallan 106 1.1 macallan sc->sc_memt = pa->pa_memt; 107 1.1 macallan sc->sc_iot = pa->pa_iot; 108 1.26 macallan sc->sc_ioctl = chipsfb_pci_ioctl; 109 1.27 macallan sc->sc_mmap = NULL; 110 1.26 macallan 111 1.1 macallan /* the framebuffer */ 112 1.27 macallan sc->sc_fb = (pci_conf_read(scp->sc_pc, scp->sc_pcitag, PCI_BAR0) & 113 1.27 macallan ~PCI_MAPREG_MEM_TYPE_MASK); 114 1.27 macallan sc->sc_fbsize = 0x01000000; /* 16MB aperture */ 115 1.27 macallan 116 1.27 macallan if (bus_space_map(sc->sc_memt, sc->sc_fb, 0x400000, 117 1.27 macallan BUS_SPACE_MAP_LINEAR, &sc->sc_fbh)) { 118 1.27 macallan aprint_error_dev(sc->sc_dev, 119 1.27 macallan "failed to map the frame buffer.\n"); 120 1.27 macallan } 121 1.27 macallan 122 1.27 macallan if (bus_space_map(sc->sc_memt, sc->sc_fb + CT_OFF_BITBLT, 0x20000, 123 1.27 macallan BUS_SPACE_MAP_LINEAR, &sc->sc_mmregh)) { 124 1.27 macallan aprint_error_dev(sc->sc_dev, 125 1.27 macallan "failed to map MMIO registers.\n"); 126 1.1 macallan } 127 1.1 macallan 128 1.1 macallan /* IO-mapped registers */ 129 1.11 macallan if (bus_space_map(sc->sc_iot, 0x0, 0x400, 0, &sc->sc_ioregh) != 0) { 130 1.26 macallan aprint_error_dev(sc->sc_dev, "failed to map IO registers.\n"); 131 1.1 macallan } 132 1.1 macallan 133 1.4 macallan sc->memsize = chipsfb_probe_vram(sc); 134 1.1 macallan 135 1.26 macallan chipsfb_do_attach(sc); 136 1.1 macallan } 137 1.1 macallan 138 1.1 macallan static int 139 1.26 macallan chipsfb_pci_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, 140 1.1 macallan struct lwp *l) 141 1.1 macallan { 142 1.1 macallan struct vcons_data *vd = v; 143 1.1 macallan struct chipsfb_softc *sc = vd->cookie; 144 1.26 macallan struct chipsfb_pci_softc *scp = vd->cookie; 145 1.1 macallan 146 1.1 macallan switch (cmd) { 147 1.23 cegger /* PCI config read/write passthrough. */ 148 1.23 cegger case PCI_IOC_CFGREAD: 149 1.23 cegger case PCI_IOC_CFGWRITE: 150 1.26 macallan return pci_devioctl(scp->sc_pc, scp->sc_pcitag, 151 1.23 cegger cmd, data, flag, l); 152 1.23 cegger 153 1.25 cegger case WSDISPLAYIO_GET_BUSID: 154 1.26 macallan return wsdisplayio_busid_pci(sc->sc_dev, scp->sc_pc, 155 1.26 macallan scp->sc_pcitag, data); 156 1.1 macallan } 157 1.1 macallan return EPASSTHROUGH; 158 1.1 macallan } 159