chipsfb.c revision 1.26 1 1.26 macallan /* $NetBSD: chipsfb.c,v 1.26 2011/02/09 21:21:32 macallan 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.26 macallan __KERNEL_RCSID(0, "$NetBSD: chipsfb.c,v 1.26 2011/02/09 21:21:32 macallan 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.1 macallan struct pci_attach_args *pa = (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.1 macallan 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.1 macallan screg |= PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
102 1.26 macallan pci_conf_write(scp->sc_pc, scp->sc_pcitag,PCI_COMMAND_STATUS_REG, screg);
103 1.8 macallan
104 1.1 macallan pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
105 1.26 macallan aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
106 1.26 macallan PCI_REVISION(pa->pa_class));
107 1.8 macallan #ifdef CHIPSFB_DEBUG
108 1.8 macallan printf(prop_dictionary_externalize(dict));
109 1.8 macallan #endif
110 1.1 macallan
111 1.1 macallan sc->sc_memt = pa->pa_memt;
112 1.1 macallan sc->sc_iot = pa->pa_iot;
113 1.26 macallan sc->sc_ioctl = chipsfb_pci_ioctl;
114 1.26 macallan
115 1.1 macallan /* the framebuffer */
116 1.1 macallan if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM,
117 1.8 macallan BUS_SPACE_MAP_LINEAR,
118 1.1 macallan &sc->sc_fbt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
119 1.26 macallan aprint_error_dev(sc->sc_dev, "failed to map the frame buffer.\n");
120 1.1 macallan }
121 1.1 macallan
122 1.1 macallan /* IO-mapped registers */
123 1.11 macallan if (bus_space_map(sc->sc_iot, 0x0, 0x400, 0, &sc->sc_ioregh) != 0) {
124 1.26 macallan aprint_error_dev(sc->sc_dev, "failed to map IO registers.\n");
125 1.1 macallan }
126 1.1 macallan
127 1.4 macallan sc->memsize = chipsfb_probe_vram(sc);
128 1.1 macallan
129 1.26 macallan chipsfb_do_attach(sc);
130 1.1 macallan }
131 1.1 macallan
132 1.1 macallan static int
133 1.26 macallan chipsfb_pci_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
134 1.1 macallan struct lwp *l)
135 1.1 macallan {
136 1.1 macallan struct vcons_data *vd = v;
137 1.1 macallan struct chipsfb_softc *sc = vd->cookie;
138 1.26 macallan struct chipsfb_pci_softc *scp = vd->cookie;
139 1.1 macallan
140 1.1 macallan switch (cmd) {
141 1.23 cegger /* PCI config read/write passthrough. */
142 1.23 cegger case PCI_IOC_CFGREAD:
143 1.23 cegger case PCI_IOC_CFGWRITE:
144 1.26 macallan return pci_devioctl(scp->sc_pc, scp->sc_pcitag,
145 1.23 cegger cmd, data, flag, l);
146 1.23 cegger
147 1.25 cegger case WSDISPLAYIO_GET_BUSID:
148 1.26 macallan return wsdisplayio_busid_pci(sc->sc_dev, scp->sc_pc,
149 1.26 macallan scp->sc_pcitag, data);
150 1.1 macallan }
151 1.1 macallan return EPASSTHROUGH;
152 1.1 macallan }
153