Sat Oct 11 20:36:40 2008 UTC ()
- use aprint_debug_dev(9) for debug info
- use aprint_normal_dev(9) rather than aprint_normal(9) + device_xname()


(tsutsui)
diff -r1.14 -r1.15 src/sys/arch/shark/ofw/vga_ofbus.c

cvs diff -r1.14 -r1.15 src/sys/arch/shark/ofw/vga_ofbus.c (switch to unified diff)

--- src/sys/arch/shark/ofw/vga_ofbus.c 2008/04/17 00:03:36 1.14
+++ src/sys/arch/shark/ofw/vga_ofbus.c 2008/10/11 20:36:40 1.15
@@ -1,222 +1,222 @@ @@ -1,222 +1,222 @@
1/* $NetBSD: vga_ofbus.c,v 1.14 2008/04/17 00:03:36 macallan Exp $ */ 1/* $NetBSD: vga_ofbus.c,v 1.15 2008/10/11 20:36:40 tsutsui Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Author: Chris G. Demetriou 7 * Author: Chris G. Demetriou
8 *  8 *
9 * Permission to use, copy, modify and distribute this software and 9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright 10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the 11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions 12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation. 13 * thereof, and that both notices appear in supporting documentation.
14 *  14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"  15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND  16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *  18 *
19 * Carnegie Mellon requests users of this software to return to 19 * Carnegie Mellon requests users of this software to return to
20 * 20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science 22 * School of Computer Science
23 * Carnegie Mellon University 23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890 24 * Pittsburgh PA 15213-3890
25 * 25 *
26 * any improvements or extensions that they make and grant Carnegie the 26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes. 27 * rights to redistribute these changes.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: vga_ofbus.c,v 1.14 2008/04/17 00:03:36 macallan Exp $"); 31__KERNEL_RCSID(0, "$NetBSD: vga_ofbus.c,v 1.15 2008/10/11 20:36:40 tsutsui Exp $");
32 32
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/systm.h> 34#include <sys/systm.h>
35#include <sys/kernel.h> 35#include <sys/kernel.h>
36#include <sys/device.h> 36#include <sys/device.h>
37#include <sys/malloc.h> 37#include <sys/malloc.h>
38#include <sys/proc.h> 38#include <sys/proc.h>
39#include <sys/kauth.h> 39#include <sys/kauth.h>
40 40
41#include <dev/isa/isavar.h> 41#include <dev/isa/isavar.h>
42 42
43#include <dev/ic/mc6845reg.h> 43#include <dev/ic/mc6845reg.h>
44#include <dev/ic/pcdisplayvar.h> 44#include <dev/ic/pcdisplayvar.h>
45#include <dev/ic/vgareg.h> 45#include <dev/ic/vgareg.h>
46#include <dev/ic/vgavar.h> 46#include <dev/ic/vgavar.h>
47 47
48#include <dev/wscons/wsconsio.h> 48#include <dev/wscons/wsconsio.h>
49#include <dev/wscons/wsdisplayvar.h> 49#include <dev/wscons/wsdisplayvar.h>
50 50
51#include <dev/ofw/openfirm.h> 51#include <dev/ofw/openfirm.h>
52 52
53#include <shark/ofw/vga_ofbusvar.h> 53#include <shark/ofw/vga_ofbusvar.h>
54 54
55struct vga_ofbus_softc { 55struct vga_ofbus_softc {
56 struct vga_softc sc_vga; 56 struct vga_softc sc_vga;
57 57
58 int sc_phandle; 58 int sc_phandle;
59}; 59};
60 60
61#if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0) 61#if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
62extern int console_ihandle; 62extern int console_ihandle;
63#endif 63#endif
64 64
65int vga_ofbus_match (device_t, cfdata_t, void *); 65int vga_ofbus_match (device_t, cfdata_t, void *);
66void vga_ofbus_attach (device_t, device_t, void *); 66void vga_ofbus_attach (device_t, device_t, void *);
67 67
68CFATTACH_DECL_NEW(vga_ofbus, sizeof(struct vga_ofbus_softc), 68CFATTACH_DECL_NEW(vga_ofbus, sizeof(struct vga_ofbus_softc),
69 vga_ofbus_match, vga_ofbus_attach, NULL, NULL); 69 vga_ofbus_match, vga_ofbus_attach, NULL, NULL);
70 70
71static const char *compat_strings[] = { "pnpPNP,900", 0 }; 71static const char *compat_strings[] = { "pnpPNP,900", 0 };
72 72
73static int vga_ofbus_ioctl(void *, u_long, void *, int, struct lwp *); 73static int vga_ofbus_ioctl(void *, u_long, void *, int, struct lwp *);
74static paddr_t vga_ofbus_mmap(void *, off_t, int); 74static paddr_t vga_ofbus_mmap(void *, off_t, int);
75 75
76static const struct vga_funcs vga_ofbus_funcs = { 76static const struct vga_funcs vga_ofbus_funcs = {
77 vga_ofbus_ioctl, 77 vga_ofbus_ioctl,
78 vga_ofbus_mmap 78 vga_ofbus_mmap
79}; 79};
80static uint32_t vga_reg[12]; 80static uint32_t vga_reg[12];
81extern paddr_t isa_io_physaddr, isa_mem_physaddr; 81extern paddr_t isa_io_physaddr, isa_mem_physaddr;
82 82
83int 83int
84vga_ofbus_match(device_t parent, cfdata_t match, void *aux) 84vga_ofbus_match(device_t parent, cfdata_t match, void *aux)
85{ 85{
86 struct ofbus_attach_args *oba = aux; 86 struct ofbus_attach_args *oba = aux;
87 87
88 if (of_compatible(oba->oba_phandle, compat_strings) == -1) 88 if (of_compatible(oba->oba_phandle, compat_strings) == -1)
89 return (0); 89 return (0);
90 90
91 if (!vga_is_console(&isa_io_bs_tag, WSDISPLAY_TYPE_ISAVGA) && 91 if (!vga_is_console(&isa_io_bs_tag, WSDISPLAY_TYPE_ISAVGA) &&
92 !vga_common_probe(&isa_io_bs_tag, &isa_mem_bs_tag)) 92 !vga_common_probe(&isa_io_bs_tag, &isa_mem_bs_tag))
93 return (0); 93 return (0);
94 94
95 return (2); /* more than generic pcdisplay */ 95 return (2); /* more than generic pcdisplay */
96} 96}
97 97
98void 98void
99vga_ofbus_attach(device_t parent, device_t self, void *aux) 99vga_ofbus_attach(device_t parent, device_t self, void *aux)
100{ 100{
101 struct vga_ofbus_softc *osc = device_private(self); 101 struct vga_ofbus_softc *osc = device_private(self);
102 struct vga_softc *sc = &osc->sc_vga; 102 struct vga_softc *sc = &osc->sc_vga;
103 struct ofbus_attach_args *oba = aux; 103 struct ofbus_attach_args *oba = aux;
104 int vga_handle, i; 104 int vga_handle, i;
105 105
106 sc->sc_dev = self; 106 sc->sc_dev = self;
107 aprint_normal("\n"); 107 aprint_normal("\n");
108 osc->sc_phandle = oba->oba_phandle; 108 osc->sc_phandle = oba->oba_phandle;
109 109
110 vga_handle = OF_finddevice("/vlbus/display"); 110 vga_handle = OF_finddevice("/vlbus/display");
111 OF_getprop(vga_handle, "reg", vga_reg, sizeof(vga_reg)); 111 OF_getprop(vga_handle, "reg", vga_reg, sizeof(vga_reg));
112 112
113 /* for some idiotic reason we get this in the wrong byte order */ 113 /* for some idiotic reason we get this in the wrong byte order */
114 for (i = 0; i < 12; i++) { 114 for (i = 0; i < 12; i++) {
115 vga_reg[i] = be32toh(vga_reg[i]); 115 vga_reg[i] = be32toh(vga_reg[i]);
116 printf("%08x\n", vga_reg[i]); 116 aprint_debug_dev(self, "vga_reg[%2d] = 0x%08x\n",
 117 i, vga_reg[i]);
117 } 118 }
118 119
119 vga_common_attach(sc, &isa_io_bs_tag, &isa_mem_bs_tag, 120 vga_common_attach(sc, &isa_io_bs_tag, &isa_mem_bs_tag,
120 WSDISPLAY_TYPE_ISAVGA, 0, &vga_ofbus_funcs); 121 WSDISPLAY_TYPE_ISAVGA, 0, &vga_ofbus_funcs);
121 if (vga_reg[10] > 0) { 122 if (vga_reg[10] > 0) {
122 aprint_normal("%s: aperture at 0x%08x\n", device_xname(self),  123 aprint_normal_dev(self, "aperture at 0x%08x\n", vga_reg[10]);
123 vga_reg[10]); 
124 } 124 }
125} 125}
126 126
127int 127int
128vga_ofbus_cnattach(bus_space_tag_t iot, bus_space_tag_t memt) 128vga_ofbus_cnattach(bus_space_tag_t iot, bus_space_tag_t memt)
129{ 129{
130 int chosen_phandle; 130 int chosen_phandle;
131 int stdout_ihandle, stdout_phandle, ret; 131 int stdout_ihandle, stdout_phandle, ret;
132 char buf[128]; 132 char buf[128];
133 133
134 stdout_phandle = 0; 134 stdout_phandle = 0;
135 135
136 /* 136 /*
137 * Find out whether the firmware's chosen stdout is 137 * Find out whether the firmware's chosen stdout is
138 * a display. If so, use the existing ihandle so the firmware 138 * a display. If so, use the existing ihandle so the firmware
139 * doesn't become Unhappy. If not, just open it. 139 * doesn't become Unhappy. If not, just open it.
140 */ 140 */
141 if ((chosen_phandle = OF_finddevice("/chosen")) == -1 || 141 if ((chosen_phandle = OF_finddevice("/chosen")) == -1 ||
142 OF_getprop(chosen_phandle, "stdout", &stdout_ihandle,  142 OF_getprop(chosen_phandle, "stdout", &stdout_ihandle,
143 sizeof(stdout_ihandle)) != sizeof(stdout_ihandle)) { 143 sizeof(stdout_ihandle)) != sizeof(stdout_ihandle)) {
144 return ENXIO; 144 return ENXIO;
145 } 145 }
146 stdout_ihandle = of_decode_int((unsigned char *)&stdout_ihandle); 146 stdout_ihandle = of_decode_int((unsigned char *)&stdout_ihandle);
147 if ((stdout_phandle = OF_instance_to_package(stdout_ihandle)) == -1 || 147 if ((stdout_phandle = OF_instance_to_package(stdout_ihandle)) == -1 ||
148 OF_getprop(stdout_phandle, "device_type", buf, sizeof(buf)) <= 0) { 148 OF_getprop(stdout_phandle, "device_type", buf, sizeof(buf)) <= 0) {
149 return ENXIO; 149 return ENXIO;
150 } 150 }
151 151
152 if (strcmp(buf, "display") != 0) { 152 if (strcmp(buf, "display") != 0) {
153 /* The display is not stdout device. */ 153 /* The display is not stdout device. */
154 return ENXIO; 154 return ENXIO;
155 } 155 }
156  156
157 if (OF_call_method("text-mode3", stdout_ihandle, 0, 0) != 0) { 157 if (OF_call_method("text-mode3", stdout_ihandle, 0, 0) != 0) {
158 printf("vga_ofbus_match: text-mode3 method invocation on VGA " 158 printf("vga_ofbus_match: text-mode3 method invocation on VGA "
159 "screen device failed\n"); 159 "screen device failed\n");
160 } 160 }
161 161
162 ret = vga_cnattach(iot, memt, WSDISPLAY_TYPE_ISAVGA, 1); 162 ret = vga_cnattach(iot, memt, WSDISPLAY_TYPE_ISAVGA, 1);
163#if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0) 163#if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
164 if (ret == 0) 164 if (ret == 0)
165 console_ihandle = stdout_ihandle; 165 console_ihandle = stdout_ihandle;
166#endif 166#endif
167 167
168 return ret; 168 return ret;
169} 169}
170 170
171static int 171static int
172vga_ofbus_ioctl(void *cookie, u_long cmd, void *data, int flag, struct lwp *l) 172vga_ofbus_ioctl(void *cookie, u_long cmd, void *data, int flag, struct lwp *l)
173{ 173{
174 /* we should catch WSDISPLAYIO_SMODE here */ 174 /* we should catch WSDISPLAYIO_SMODE here */
175 return 0; 175 return 0;
176} 176}
177 177
178static paddr_t 178static paddr_t
179vga_ofbus_mmap(void *cookie, off_t offset, int prot) 179vga_ofbus_mmap(void *cookie, off_t offset, int prot)
180{ 180{
181 181
182 /* only the superuser may mmap IO and aperture */ 182 /* only the superuser may mmap IO and aperture */
183 if (curlwp != NULL) { 183 if (curlwp != NULL) {
184 if (kauth_authorize_generic(kauth_cred_get(), 184 if (kauth_authorize_generic(kauth_cred_get(),
185 KAUTH_GENERIC_ISSUSER, NULL) != 0) { 185 KAUTH_GENERIC_ISSUSER, NULL) != 0) {
186 return -1; 186 return -1;
187 } 187 }
188 } 188 }
189 189
190 /* 190 /*
191 * XXX 191 * XXX
192 * we should really use bus_space_mmap here but for some reason 192 * we should really use bus_space_mmap here but for some reason
193 * the ISA tags contain kernel virtual addresses and translating them 193 * the ISA tags contain kernel virtual addresses and translating them
194 * back to physical addresses doesn't really work 194 * back to physical addresses doesn't really work
195 */ 195 */
196 /* access to IO ports */ 196 /* access to IO ports */
197 if ((offset >= PCI_MAGIC_IO_RANGE) && 197 if ((offset >= PCI_MAGIC_IO_RANGE) &&
198 (offset < (PCI_MAGIC_IO_RANGE + 0x10000))) { 198 (offset < (PCI_MAGIC_IO_RANGE + 0x10000))) {
199 paddr_t pa; 199 paddr_t pa;
200 200
201 pa = isa_io_physaddr + offset - PCI_MAGIC_IO_RANGE; 201 pa = isa_io_physaddr + offset - PCI_MAGIC_IO_RANGE;
202 return arm_btop(pa); 202 return arm_btop(pa);
203 } 203 }
204 204
205 /* legacy VGA aperture */ 205 /* legacy VGA aperture */
206 if ((offset >= 0xa0000) && (offset < 0xc0000)) { 206 if ((offset >= 0xa0000) && (offset < 0xc0000)) {
207 207
208 return arm_btop(isa_mem_physaddr + offset); 208 return arm_btop(isa_mem_physaddr + offset);
209 } 209 }
210 210
211 /* SVGA aperture, we get the address from OpenFirmware */ 211 /* SVGA aperture, we get the address from OpenFirmware */
212 if (vga_reg[10] == 0) 212 if (vga_reg[10] == 0)
213 return -1; 213 return -1;
214 214
215 if ((offset >= vga_reg[10]) && 215 if ((offset >= vga_reg[10]) &&
216 (offset < (vga_reg[10] + vga_reg[11]))) { 216 (offset < (vga_reg[10] + vga_reg[11]))) {
217 217
218 return arm_btop(isa_mem_physaddr + offset); 218 return arm_btop(isa_mem_physaddr + offset);
219 } 219 }
220 220
221 return -1; 221 return -1;
222} 222}