Home | History | Annotate | Line # | Download | only in pci
vga_pci.c revision 1.6
      1  1.6   thorpej /* $NetBSD: vga_pci.c,v 1.6 2001/09/14 06:46:08 thorpej Exp $ */
      2  1.1  drochner 
      3  1.1  drochner /*
      4  1.1  drochner  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  1.1  drochner  * All rights reserved.
      6  1.1  drochner  *
      7  1.1  drochner  * Author: Chris G. Demetriou
      8  1.1  drochner  *
      9  1.1  drochner  * Permission to use, copy, modify and distribute this software and
     10  1.1  drochner  * its documentation is hereby granted, provided that both the copyright
     11  1.1  drochner  * notice and this permission notice appear in all copies of the
     12  1.1  drochner  * software, derivative works or modified versions, and any portions
     13  1.1  drochner  * thereof, and that both notices appear in supporting documentation.
     14  1.1  drochner  *
     15  1.1  drochner  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.1  drochner  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  1.1  drochner  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  1.1  drochner  *
     19  1.1  drochner  * Carnegie Mellon requests users of this software to return to
     20  1.1  drochner  *
     21  1.1  drochner  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  1.1  drochner  *  School of Computer Science
     23  1.1  drochner  *  Carnegie Mellon University
     24  1.1  drochner  *  Pittsburgh PA 15213-3890
     25  1.1  drochner  *
     26  1.1  drochner  * any improvements or extensions that they make and grant Carnegie the
     27  1.1  drochner  * rights to redistribute these changes.
     28  1.1  drochner  */
     29  1.1  drochner 
     30  1.1  drochner #include <sys/param.h>
     31  1.1  drochner #include <sys/systm.h>
     32  1.1  drochner #include <sys/kernel.h>
     33  1.1  drochner #include <sys/device.h>
     34  1.1  drochner #include <sys/malloc.h>
     35  1.1  drochner 
     36  1.1  drochner #include <dev/pci/pcireg.h>
     37  1.1  drochner #include <dev/pci/pcivar.h>
     38  1.1  drochner #include <dev/pci/pcidevs.h>
     39  1.6   thorpej #include <dev/pci/pciio.h>
     40  1.1  drochner 
     41  1.2  drochner #include <dev/ic/mc6845reg.h>
     42  1.2  drochner #include <dev/ic/pcdisplayvar.h>
     43  1.1  drochner #include <dev/ic/vgareg.h>
     44  1.1  drochner #include <dev/ic/vgavar.h>
     45  1.1  drochner #include <dev/pci/vga_pcivar.h>
     46  1.1  drochner 
     47  1.1  drochner #include <dev/wscons/wsconsio.h>
     48  1.1  drochner #include <dev/wscons/wsdisplayvar.h>
     49  1.1  drochner 
     50  1.1  drochner struct vga_pci_softc {
     51  1.5   thorpej 	struct vga_softc sc_vga;
     52  1.5   thorpej 
     53  1.6   thorpej 	pci_chipset_tag_t sc_pc;
     54  1.5   thorpej 	pcitag_t sc_pcitag;
     55  1.1  drochner };
     56  1.1  drochner 
     57  1.1  drochner int	vga_pci_match __P((struct device *, struct cfdata *, void *));
     58  1.1  drochner void	vga_pci_attach __P((struct device *, struct device *, void *));
     59  1.1  drochner 
     60  1.1  drochner struct cfattach vga_pci_ca = {
     61  1.1  drochner 	sizeof(struct vga_pci_softc), vga_pci_match, vga_pci_attach,
     62  1.1  drochner };
     63  1.1  drochner 
     64  1.6   thorpej int	vga_pci_ioctl(void *, u_long, caddr_t, int, struct proc *);
     65  1.6   thorpej paddr_t	vga_pci_mmap(void *, off_t, int);
     66  1.6   thorpej 
     67  1.6   thorpej const struct vga_funcs vga_pci_funcs = {
     68  1.6   thorpej 	vga_pci_ioctl,
     69  1.6   thorpej 	vga_pci_mmap,
     70  1.6   thorpej };
     71  1.6   thorpej 
     72  1.1  drochner int
     73  1.1  drochner vga_pci_match(parent, match, aux)
     74  1.1  drochner 	struct device *parent;
     75  1.1  drochner 	struct cfdata *match;
     76  1.1  drochner 	void *aux;
     77  1.1  drochner {
     78  1.1  drochner 	struct pci_attach_args *pa = aux;
     79  1.1  drochner 	int potential;
     80  1.1  drochner 
     81  1.1  drochner 	potential = 0;
     82  1.1  drochner 
     83  1.1  drochner 	/*
     84  1.1  drochner 	 * If it's prehistoric/vga or display/vga, we might match.
     85  1.1  drochner 	 * For the console device, this is jut a sanity check.
     86  1.1  drochner 	 */
     87  1.1  drochner 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PREHISTORIC &&
     88  1.1  drochner 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PREHISTORIC_VGA)
     89  1.1  drochner 		potential = 1;
     90  1.1  drochner 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY &&
     91  1.1  drochner 	     PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_DISPLAY_VGA)
     92  1.1  drochner 		potential = 1;
     93  1.1  drochner 
     94  1.1  drochner 	if (!potential)
     95  1.1  drochner 		return (0);
     96  1.1  drochner 
     97  1.1  drochner 	/* check whether it is disabled by firmware */
     98  1.1  drochner 	if ((pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG)
     99  1.1  drochner 	    & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE))
    100  1.1  drochner 	    != (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE))
    101  1.1  drochner 		return (0);
    102  1.1  drochner 
    103  1.1  drochner 	/* If it's the console, we have a winner! */
    104  1.1  drochner 	if (vga_is_console(pa->pa_iot, WSDISPLAY_TYPE_PCIVGA))
    105  1.1  drochner 		return (1);
    106  1.1  drochner 
    107  1.1  drochner 	/*
    108  1.1  drochner 	 * If we might match, make sure that the card actually looks OK.
    109  1.1  drochner 	 */
    110  1.1  drochner 	if (!vga_common_probe(pa->pa_iot, pa->pa_memt))
    111  1.1  drochner 		return (0);
    112  1.1  drochner 
    113  1.1  drochner 	return (1);
    114  1.1  drochner }
    115  1.1  drochner 
    116  1.1  drochner void
    117  1.1  drochner vga_pci_attach(parent, self, aux)
    118  1.1  drochner 	struct device *parent, *self;
    119  1.1  drochner 	void *aux;
    120  1.1  drochner {
    121  1.5   thorpej 	struct vga_pci_softc *psc = (void *) self;
    122  1.5   thorpej 	struct vga_softc *sc = &psc->sc_vga;
    123  1.1  drochner 	struct pci_attach_args *pa = aux;
    124  1.1  drochner 	char devinfo[256];
    125  1.1  drochner 
    126  1.6   thorpej 	psc->sc_pc = pa->pa_pc;
    127  1.5   thorpej 	psc->sc_pcitag = pa->pa_tag;
    128  1.1  drochner 
    129  1.1  drochner 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    130  1.1  drochner 	printf(": %s (rev. 0x%02x)\n", devinfo,
    131  1.1  drochner 	    PCI_REVISION(pa->pa_class));
    132  1.1  drochner 
    133  1.5   thorpej 	vga_common_attach(sc, pa->pa_iot, pa->pa_memt, WSDISPLAY_TYPE_PCIVGA,
    134  1.6   thorpej 	    &vga_pci_funcs);
    135  1.1  drochner }
    136  1.1  drochner 
    137  1.1  drochner int
    138  1.1  drochner vga_pci_cnattach(iot, memt, pc, bus, device, function)
    139  1.1  drochner 	bus_space_tag_t iot, memt;
    140  1.1  drochner 	pci_chipset_tag_t pc;
    141  1.1  drochner 	int bus, device, function;
    142  1.1  drochner {
    143  1.1  drochner 	return (vga_cnattach(iot, memt, WSDISPLAY_TYPE_PCIVGA, 0));
    144  1.6   thorpej }
    145  1.6   thorpej 
    146  1.6   thorpej int
    147  1.6   thorpej vga_pci_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    148  1.6   thorpej {
    149  1.6   thorpej 	struct vga_config *vc = v;
    150  1.6   thorpej 	struct vga_pci_softc *psc = (void *) vc->softc;
    151  1.6   thorpej 
    152  1.6   thorpej 	switch (cmd) {
    153  1.6   thorpej 	/* PCI config read/write passthrough. */
    154  1.6   thorpej 	case PCI_IOC_CFGREAD:
    155  1.6   thorpej 	case PCI_IOC_CFGWRITE:
    156  1.6   thorpej 		return (pci_devioctl(psc->sc_pc, psc->sc_pcitag,
    157  1.6   thorpej 		    cmd, data, flag, p));
    158  1.6   thorpej 
    159  1.6   thorpej 	default:
    160  1.6   thorpej 		return (ENOTTY);
    161  1.6   thorpej 	}
    162  1.6   thorpej }
    163  1.6   thorpej 
    164  1.6   thorpej paddr_t
    165  1.6   thorpej vga_pci_mmap(void *v, off_t offset, int prot)
    166  1.6   thorpej {
    167  1.6   thorpej 
    168  1.6   thorpej 	/* XXX Fill me in. */
    169  1.6   thorpej 	return (-1);
    170  1.1  drochner }
    171