grf_nubus.c revision 1.7 1 /* $NetBSD: grf_nubus.c,v 1.7 1995/08/24 04:27:16 briggs Exp $ */
2
3 /*
4 * Copyright (c) 1995 Allen Briggs. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Allen Briggs.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 /*
32 * Device-specific routines for handling Nubus-based video cards.
33 */
34
35 #include <sys/param.h>
36
37 #include <sys/device.h>
38 #include <sys/ioctl.h>
39 #include <sys/file.h>
40 #include <sys/malloc.h>
41 #include <sys/mman.h>
42 #include <sys/proc.h>
43
44 #include <machine/grfioctl.h>
45 #include <machine/cpu.h>
46
47 #include "nubus.h"
48 #include "grfvar.h"
49
50 extern int grfmv_probe __P((struct grf_softc *gp, nubus_slot *slot));
51 extern int grfmv_init __P((struct grf_softc *gp));
52 extern int grfmv_mode __P((struct grf_softc *gp, int cmd, void *arg));
53
54 static char zero = 0;
55
56 static void
57 load_image_data(data, image)
58 caddr_t data;
59 struct image_data *image;
60 {
61 bcopy(data , &image->size, 4);
62 bcopy(data + 4, &image->offset, 4);
63 bcopy(data + 8, &image->rowbytes, 2);
64 bcopy(data + 10, &image->top, 2);
65 bcopy(data + 12, &image->left, 2);
66 bcopy(data + 14, &image->bottom, 2);
67 bcopy(data + 16, &image->right, 2);
68 bcopy(data + 18, &image->version, 2);
69 bcopy(data + 20, &image->packType, 2);
70 bcopy(data + 22, &image->packSize, 4);
71 bcopy(data + 26, &image->hRes, 4);
72 bcopy(data + 30, &image->vRes, 4);
73 bcopy(data + 34, &image->pixelType, 2);
74 bcopy(data + 36, &image->pixelSize, 2);
75 bcopy(data + 38, &image->cmpCount, 2);
76 bcopy(data + 40, &image->cmpSize, 2);
77 bcopy(data + 42, &image->planeBytes, 4);
78 }
79
80 static void
81 grfmv_intr(sc, slot)
82 struct grf_softc *sc;
83 int slot;
84 {
85 struct grf_softc *gp;
86 caddr_t slotbase;
87
88 slotbase = (caddr_t) NUBUS_SLOT_TO_BASE(slot);
89 slotbase[0xa0000] = zero;
90 }
91
92 static int
93 get_vrsrcid(slot)
94 nubus_slot *slot;
95 {
96 extern u_short mac68k_vrsrc_vec[];
97 extern int mac68k_vrsrc_cnt;
98 int i;
99
100 for (i = 0 ; i < 6 ; i++)
101 if ((mac68k_vrsrc_vec[i] & 0xff) == slot->slot)
102 return ((mac68k_vrsrc_vec[i] >> 8) & 0xff);
103 return 0x80;
104 }
105
106 extern int
107 grfmv_probe(sc, slot)
108 struct grf_softc *sc;
109 nubus_slot *slot;
110 {
111 nubus_dir dir, *dirp, dir2, *dirp2;
112 nubus_dirent dirent, *direntp;
113 nubus_type slottype;
114 int vrsrc;
115
116 dirp = &dir;
117 direntp = &dirent;
118 nubus_get_main_dir(slot, dirp);
119
120 vrsrc = get_vrsrcid(slot);
121 if (nubus_find_rsrc(slot, dirp, vrsrc, direntp) <= 0) {
122 if ( (vrsrc != 128)
123 || (nubus_find_rsrc(slot, dirp, 129, direntp) <= 0)) {
124 return 0;
125 }
126 }
127
128 dirp2 = (nubus_dir *) &sc->board_dir;
129 nubus_get_dir_from_rsrc(slot, direntp, dirp2);
130
131 if (nubus_find_rsrc(slot, dirp2, NUBUS_RSRC_TYPE, direntp) <= 0)
132 /* Type is a required entry... This should never happen. */
133 return 0;
134
135 if (nubus_get_ind_data(slot, direntp,
136 (caddr_t) &slottype, sizeof(nubus_type)) <= 0)
137 return 0;
138
139 if (slottype.category != NUBUS_CATEGORY_DISPLAY)
140 return 0;
141
142 if (slottype.type != NUBUS_TYPE_VIDEO)
143 return 0;
144
145 if (slottype.drsw != NUBUS_DRSW_APPLE)
146 return 0;
147
148 /*
149 * If we've gotten this far, then we're dealing with a real-live
150 * Apple QuickDraw-compatible display card resource. Now, how to
151 * determine that this is an active resource??? Dunno. But we'll
152 * proceed like it is.
153 */
154
155 sc->card_id = slottype.drhw;
156
157 /* Need to load display info (and driver?), etc... */
158
159 return 1;
160 }
161
162 extern int
163 grfmv_init(sc)
164 struct grf_softc *sc;
165 {
166 struct image_data image_store, image;
167 nubus_dirent dirent;
168 nubus_dir mode_dir;
169 int mode;
170 u_long base;
171
172 mode = NUBUS_RSRC_FIRSTMODE;
173 if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0)
174 return 0;
175
176 nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
177
178 if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent) <= 0)
179 return 0;
180
181 if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t) &image_store,
182 sizeof(struct image_data)) <= 0)
183 return 0;
184
185 load_image_data((caddr_t) &image_store, &image);
186
187 base = NUBUS_SLOT_TO_BASE(sc->sc_slot.slot);
188
189 sc->curr_mode.mode_id = mode;
190 sc->curr_mode.fbbase = (caddr_t) (base + image.offset);
191 sc->curr_mode.fboff = image.offset;
192 sc->curr_mode.rowbytes = image.rowbytes;
193 sc->curr_mode.width = image.right - image.left;
194 sc->curr_mode.height = image.bottom - image.top;
195 sc->curr_mode.fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
196 sc->curr_mode.hres = image.hRes;
197 sc->curr_mode.vres = image.vRes;
198 sc->curr_mode.ptype = image.pixelType;
199 sc->curr_mode.psize = image.pixelSize;
200
201 strncpy(sc->card_name, nubus_get_card_name(&sc->sc_slot),
202 CARD_NAME_LEN);
203
204 sc->card_name[CARD_NAME_LEN-1] = '\0';
205
206 add_nubus_intr(sc->sc_slot.slot, grfmv_intr, sc);
207
208 return 1;
209 }
210
211 extern int
212 grfmv_mode(gp, cmd, arg)
213 struct grf_softc *gp;
214 int cmd;
215 void *arg;
216 {
217 switch (cmd) {
218 case GM_GRFON:
219 case GM_GRFOFF:
220 return 0;
221 case GM_CURRMODE:
222 break;
223 case GM_NEWMODE:
224 break;
225 case GM_LISTMODES:
226 break;
227 }
228 return EINVAL;
229 }
230
231 extern caddr_t
232 grfmv_phys(gp, addr)
233 struct grf_softc *gp;
234 vm_offset_t addr;
235 {
236 return (caddr_t) NUBUS_VIRT_TO_PHYS(addr);
237 }
238