grf_nubus.c revision 1.1 1 /* $NetBSD: grf_nubus.c,v 1.1 1995/04/29 20:23:42 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
87 ((char *) (((u_long) (0xf0 | slot)) << 24))[0xa0000] = zero;
88 }
89
90 extern int
91 grfmv_probe(sc, slot)
92 struct grf_softc *sc;
93 nubus_slot *slot;
94 {
95 nubus_dir dir, *dirp, dir2, *dirp2;
96 nubus_dirent dirent, *direntp;
97 nubus_type slottype;
98
99 dirp = &dir;
100 direntp = &dirent;
101 nubus_get_main_dir(slot, dirp);
102
103 /*
104 * Unfortunately, I think we'll have to load this value from
105 * the macos. The alternative is putting in enough hooks to
106 * be able to call the card's PrimaryInit routine which could
107 * call just about any part of the ROM, I think.
108 */
109 if (nubus_find_rsrc(slot, dirp, 128, direntp) <= 0) {
110 if (nubus_find_rsrc(slot, dirp, 129, direntp) <= 0) {
111 return 0;
112 }
113 }
114
115 dirp2 = (nubus_dir *) &sc->board_dir;
116 nubus_get_dir_from_rsrc(slot, direntp, dirp2);
117
118 if (nubus_find_rsrc(slot, dirp2, NUBUS_RSRC_TYPE, direntp) <= 0)
119 /* Type is a required entry... This should never happen. */
120 return 0;
121
122 if (nubus_get_ind_data(slot, direntp,
123 (caddr_t) &slottype, sizeof(nubus_type)) <= 0)
124 return 0;
125
126 if (slottype.category != NUBUS_CATEGORY_DISPLAY)
127 return 0;
128
129 if (slottype.type != NUBUS_TYPE_VIDEO)
130 return 0;
131
132 if (slottype.drsw != NUBUS_DRSW_APPLE)
133 return 0;
134
135 /*
136 * If we've gotten this far, then we're dealing with a real-live
137 * Apple QuickDraw-compatible display card resource. Now, how to
138 * determine that this is an active resource??? Dunno. But we'll
139 * proceed like it is.
140 */
141
142 sc->card_id = slottype.drhw;
143 printf("card id = 0x%x.\n", sc->card_id);
144
145 /* Need to load display info (and driver?), etc... */
146
147 return 1;
148 }
149
150 extern int
151 grfmv_init(sc)
152 struct grf_softc *sc;
153 {
154 struct image_data image_store, image;
155 nubus_dirent dirent;
156 nubus_dir mode_dir;
157 int mode;
158 u_long base;
159
160 mode = NUBUS_RSRC_FIRSTMODE;
161 if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0)
162 return 0;
163
164 nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
165
166 if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent) <= 0)
167 return 0;
168
169 if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t) &image_store,
170 sizeof(struct image_data)) <= 0)
171 return 0;
172
173 load_image_data((caddr_t) &image_store, &image);
174
175 base = NUBUS_SLOT_TO_BASE(sc->sc_slot.slot);
176
177 sc->curr_mode.mode_id = mode;
178 sc->curr_mode.fbbase = (caddr_t) (base + image.offset);
179 sc->curr_mode.rowbytes = image.rowbytes;
180 sc->curr_mode.width = image.right - image.left;
181 sc->curr_mode.height = image.bottom - image.top;
182 sc->curr_mode.fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
183 sc->curr_mode.hres = image.hRes;
184 sc->curr_mode.vres = image.vRes;
185 sc->curr_mode.ptype = image.pixelType;
186 sc->curr_mode.psize = image.pixelSize;
187
188 strncpy(sc->card_name, nubus_get_card_name(&sc->sc_slot),
189 CARD_NAME_LEN);
190
191 sc->card_name[CARD_NAME_LEN-1] = '\0';
192
193 add_nubus_intr(sc->sc_slot.slot, grfmv_intr, sc);
194
195 return 1;
196 }
197
198 extern int
199 grfmv_mode(gp, cmd, arg)
200 struct grf_softc *gp;
201 int cmd;
202 void *arg;
203 {
204 switch (cmd) {
205 case GM_CURRMODE:
206 break;
207 case GM_NEWMODE:
208 break;
209 case GM_LISTMODES:
210 break;
211 }
212 return EINVAL;
213 }
214