Home | History | Annotate | Line # | Download | only in pci
chipsfb.c revision 1.29
      1  1.29    dyoung /*	$NetBSD: chipsfb.c,v 1.29 2011/05/11 00:12:41 dyoung 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.29    dyoung __KERNEL_RCSID(0, "$NetBSD: chipsfb.c,v 1.29 2011/05/11 00:12:41 dyoung 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 	char devinfo[256];
     93   1.1  macallan 	pcireg_t screg;
     94   1.1  macallan 
     95  1.26  macallan 	scp->sc_pc = pa->pa_pc;
     96  1.26  macallan 	scp->sc_pcitag = pa->pa_tag;
     97  1.26  macallan 	sc->sc_dev = self;
     98  1.26  macallan 
     99  1.26  macallan 	screg = pci_conf_read(scp->sc_pc, scp->sc_pcitag,
    100  1.26  macallan 	    PCI_COMMAND_STATUS_REG);
    101  1.28    dyoung 	screg |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE;
    102  1.27  macallan 	pci_conf_write(scp->sc_pc, scp->sc_pcitag, PCI_COMMAND_STATUS_REG,
    103  1.27  macallan 	    screg);
    104   1.8  macallan 
    105   1.1  macallan 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    106  1.26  macallan 	aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
    107  1.26  macallan 	    PCI_REVISION(pa->pa_class));
    108   1.8  macallan #ifdef CHIPSFB_DEBUG
    109   1.8  macallan 	printf(prop_dictionary_externalize(dict));
    110   1.8  macallan #endif
    111   1.1  macallan 
    112   1.1  macallan 	sc->sc_memt = pa->pa_memt;
    113   1.1  macallan 	sc->sc_iot = pa->pa_iot;
    114  1.26  macallan 	sc->sc_ioctl = chipsfb_pci_ioctl;
    115  1.27  macallan 	sc->sc_mmap = NULL;
    116  1.26  macallan 
    117   1.1  macallan 	/* the framebuffer */
    118  1.27  macallan 	sc->sc_fb = (pci_conf_read(scp->sc_pc, scp->sc_pcitag, PCI_BAR0) &
    119  1.27  macallan 	    ~PCI_MAPREG_MEM_TYPE_MASK);
    120  1.27  macallan 	sc->sc_fbsize = 0x01000000;	/* 16MB aperture */
    121  1.27  macallan 
    122  1.27  macallan 	if (bus_space_map(sc->sc_memt, sc->sc_fb, 0x400000,
    123  1.27  macallan 	    BUS_SPACE_MAP_LINEAR, &sc->sc_fbh)) {
    124  1.27  macallan 		aprint_error_dev(sc->sc_dev,
    125  1.27  macallan 		    "failed to map the frame buffer.\n");
    126  1.27  macallan 	}
    127  1.27  macallan 
    128  1.27  macallan 	if (bus_space_map(sc->sc_memt, sc->sc_fb + CT_OFF_BITBLT, 0x20000,
    129  1.27  macallan 	    BUS_SPACE_MAP_LINEAR, &sc->sc_mmregh)) {
    130  1.27  macallan 		aprint_error_dev(sc->sc_dev,
    131  1.27  macallan 		    "failed to map MMIO registers.\n");
    132   1.1  macallan 	}
    133   1.1  macallan 
    134   1.1  macallan 	/* IO-mapped registers */
    135  1.11  macallan 	if (bus_space_map(sc->sc_iot, 0x0, 0x400, 0, &sc->sc_ioregh) != 0) {
    136  1.26  macallan 		aprint_error_dev(sc->sc_dev, "failed to map IO registers.\n");
    137   1.1  macallan 	}
    138   1.1  macallan 
    139   1.4  macallan 	sc->memsize = chipsfb_probe_vram(sc);
    140   1.1  macallan 
    141  1.26  macallan 	chipsfb_do_attach(sc);
    142   1.1  macallan }
    143   1.1  macallan 
    144   1.1  macallan static int
    145  1.26  macallan chipsfb_pci_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    146   1.1  macallan 	struct lwp *l)
    147   1.1  macallan {
    148   1.1  macallan 	struct vcons_data *vd = v;
    149   1.1  macallan 	struct chipsfb_softc *sc = vd->cookie;
    150  1.26  macallan 	struct chipsfb_pci_softc *scp = vd->cookie;
    151   1.1  macallan 
    152   1.1  macallan 	switch (cmd) {
    153  1.23    cegger 	/* PCI config read/write passthrough. */
    154  1.23    cegger 	case PCI_IOC_CFGREAD:
    155  1.23    cegger 	case PCI_IOC_CFGWRITE:
    156  1.26  macallan 		return pci_devioctl(scp->sc_pc, scp->sc_pcitag,
    157  1.23    cegger 		    cmd, data, flag, l);
    158  1.23    cegger 
    159  1.25    cegger 	case WSDISPLAYIO_GET_BUSID:
    160  1.26  macallan 		return wsdisplayio_busid_pci(sc->sc_dev, scp->sc_pc,
    161  1.26  macallan 		    scp->sc_pcitag, data);
    162   1.1  macallan 	}
    163   1.1  macallan 	return EPASSTHROUGH;
    164   1.1  macallan }
    165