| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: genfb_pci.c,v 1.27 2011/01/22 15:14:28 cegger Exp $ */ | | 1 | /* $NetBSD: genfb_pci.c,v 1.28 2011/02/09 13:19:53 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2007 Michael Lorenz | | 4 | * Copyright (c) 2007 Michael Lorenz |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: genfb_pci.c,v 1.27 2011/01/22 15:14:28 cegger Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: genfb_pci.c,v 1.28 2011/02/09 13:19:53 jmcneill Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/systm.h> | | 33 | #include <sys/systm.h> |
34 | #include <sys/kernel.h> | | 34 | #include <sys/kernel.h> |
35 | #include <sys/device.h> | | 35 | #include <sys/device.h> |
36 | #include <sys/proc.h> | | 36 | #include <sys/proc.h> |
37 | #include <sys/mutex.h> | | 37 | #include <sys/mutex.h> |
38 | #include <sys/ioctl.h> | | 38 | #include <sys/ioctl.h> |
39 | #include <sys/kernel.h> | | 39 | #include <sys/kernel.h> |
40 | #include <sys/systm.h> | | 40 | #include <sys/systm.h> |
41 | #include <sys/kauth.h> | | 41 | #include <sys/kauth.h> |
42 | | | 42 | |
43 | #include <dev/pci/pcidevs.h> | | 43 | #include <dev/pci/pcidevs.h> |
| @@ -56,26 +56,27 @@ __KERNEL_RCSID(0, "$NetBSD: genfb_pci.c, | | | @@ -56,26 +56,27 @@ __KERNEL_RCSID(0, "$NetBSD: genfb_pci.c, |
56 | #ifdef GENFB_PCI_DEBUG | | 56 | #ifdef GENFB_PCI_DEBUG |
57 | # define DPRINTF printf | | 57 | # define DPRINTF printf |
58 | #else | | 58 | #else |
59 | # define DPRINTF while (0) printf | | 59 | # define DPRINTF while (0) printf |
60 | #endif | | 60 | #endif |
61 | | | 61 | |
62 | static int pci_genfb_match(device_t, cfdata_t, void *); | | 62 | static int pci_genfb_match(device_t, cfdata_t, void *); |
63 | static void pci_genfb_attach(device_t, device_t, void *); | | 63 | static void pci_genfb_attach(device_t, device_t, void *); |
64 | static int pci_genfb_ioctl(void *, void *, u_long, void *, int, | | 64 | static int pci_genfb_ioctl(void *, void *, u_long, void *, int, |
65 | struct lwp *); | | 65 | struct lwp *); |
66 | static paddr_t pci_genfb_mmap(void *, void *, off_t, int); | | 66 | static paddr_t pci_genfb_mmap(void *, void *, off_t, int); |
67 | static int pci_genfb_borrow(void *, bus_addr_t, bus_space_handle_t *); | | 67 | static int pci_genfb_borrow(void *, bus_addr_t, bus_space_handle_t *); |
68 | static int pci_genfb_drm_print(void *, const char *); | | 68 | static int pci_genfb_drm_print(void *, const char *); |
| | | 69 | static bool pci_genfb_shutdown(device_t, int); |
69 | | | 70 | |
70 | CFATTACH_DECL_NEW(genfb_pci, sizeof(struct pci_genfb_softc), | | 71 | CFATTACH_DECL_NEW(genfb_pci, sizeof(struct pci_genfb_softc), |
71 | pci_genfb_match, pci_genfb_attach, NULL, NULL); | | 72 | pci_genfb_match, pci_genfb_attach, NULL, NULL); |
72 | | | 73 | |
73 | static int | | 74 | static int |
74 | pci_genfb_match(device_t parent, cfdata_t match, void *aux) | | 75 | pci_genfb_match(device_t parent, cfdata_t match, void *aux) |
75 | { | | 76 | { |
76 | struct pci_attach_args *pa = aux; | | 77 | struct pci_attach_args *pa = aux; |
77 | int matchlvl = 1; | | 78 | int matchlvl = 1; |
78 | | | 79 | |
79 | if (!genfb_is_enabled()) | | 80 | if (!genfb_is_enabled()) |
80 | return 0; /* explicitly disabled by MD code */ | | 81 | return 0; /* explicitly disabled by MD code */ |
81 | | | 82 | |
| @@ -107,31 +108,33 @@ pci_genfb_attach(device_t parent, device | | | @@ -107,31 +108,33 @@ pci_genfb_attach(device_t parent, device |
107 | aprint_normal(": %s\n", devinfo); | | 108 | aprint_normal(": %s\n", devinfo); |
108 | | | 109 | |
109 | sc->sc_gen.sc_dev = self; | | 110 | sc->sc_gen.sc_dev = self; |
110 | sc->sc_memt = pa->pa_memt; | | 111 | sc->sc_memt = pa->pa_memt; |
111 | sc->sc_iot = pa->pa_iot; | | 112 | sc->sc_iot = pa->pa_iot; |
112 | sc->sc_pc = pa->pa_pc; | | 113 | sc->sc_pc = pa->pa_pc; |
113 | sc->sc_pcitag = pa->pa_tag; | | 114 | sc->sc_pcitag = pa->pa_tag; |
114 | sc->sc_want_wsfb = 0; | | 115 | sc->sc_want_wsfb = 0; |
115 | | | 116 | |
116 | genfb_init(&sc->sc_gen); | | 117 | genfb_init(&sc->sc_gen); |
117 | | | 118 | |
118 | /* firmware / MD code responsible for restoring the display */ | | 119 | /* firmware / MD code responsible for restoring the display */ |
119 | if (sc->sc_gen.sc_pmfcb == NULL) | | 120 | if (sc->sc_gen.sc_pmfcb == NULL) |
120 | pmf_device_register(self, NULL, NULL); | | 121 | pmf_device_register1(self, NULL, NULL, |
| | | 122 | pci_genfb_shutdown); |
121 | else | | 123 | else |
122 | pmf_device_register(self, | | 124 | pmf_device_register1(self, |
123 | sc->sc_gen.sc_pmfcb->gpc_suspend, | | 125 | sc->sc_gen.sc_pmfcb->gpc_suspend, |
124 | sc->sc_gen.sc_pmfcb->gpc_resume); | | 126 | sc->sc_gen.sc_pmfcb->gpc_resume, |
| | | 127 | pci_genfb_shutdown); |
125 | | | 128 | |
126 | if ((sc->sc_gen.sc_width == 0) || (sc->sc_gen.sc_fbsize == 0)) { | | 129 | if ((sc->sc_gen.sc_width == 0) || (sc->sc_gen.sc_fbsize == 0)) { |
127 | aprint_debug_dev(self, "not configured by firmware\n"); | | 130 | aprint_debug_dev(self, "not configured by firmware\n"); |
128 | return; | | 131 | return; |
129 | } | | 132 | } |
130 | | | 133 | |
131 | if (bus_space_map(sc->sc_memt, sc->sc_gen.sc_fboffset, | | 134 | if (bus_space_map(sc->sc_memt, sc->sc_gen.sc_fboffset, |
132 | sc->sc_gen.sc_fbsize, BUS_SPACE_MAP_LINEAR, &sc->sc_memh) != 0) { | | 135 | sc->sc_gen.sc_fbsize, BUS_SPACE_MAP_LINEAR, &sc->sc_memh) != 0) { |
133 | | | 136 | |
134 | aprint_error_dev(self, "unable to map the framebuffer\n"); | | 137 | aprint_error_dev(self, "unable to map the framebuffer\n"); |
135 | return; | | 138 | return; |
136 | } | | 139 | } |
137 | sc->sc_gen.sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_memh); | | 140 | sc->sc_gen.sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_memh); |
| @@ -316,13 +319,20 @@ int | | | @@ -316,13 +319,20 @@ int |
316 | pci_genfb_borrow(void *opaque, bus_addr_t addr, bus_space_handle_t *hdlp) | | 319 | pci_genfb_borrow(void *opaque, bus_addr_t addr, bus_space_handle_t *hdlp) |
317 | { | | 320 | { |
318 | struct pci_genfb_softc *sc = opaque; | | 321 | struct pci_genfb_softc *sc = opaque; |
319 | | | 322 | |
320 | if (sc == NULL) | | 323 | if (sc == NULL) |
321 | return 0; | | 324 | return 0; |
322 | if (!sc->sc_gen.sc_fboffset) | | 325 | if (!sc->sc_gen.sc_fboffset) |
323 | return 0; | | 326 | return 0; |
324 | if (sc->sc_gen.sc_fboffset != addr) | | 327 | if (sc->sc_gen.sc_fboffset != addr) |
325 | return 0; | | 328 | return 0; |
326 | *hdlp = sc->sc_memh; | | 329 | *hdlp = sc->sc_memh; |
327 | return 1; | | 330 | return 1; |
328 | } | | 331 | } |
| | | 332 | |
| | | 333 | static bool |
| | | 334 | pci_genfb_shutdown(device_t self, int flags) |
| | | 335 | { |
| | | 336 | genfb_enable_polling(self); |
| | | 337 | return true; |
| | | 338 | } |