grf_cc.c revision 1.25 1 /* $NetBSD: grf_cc.c,v 1.25 1998/07/10 20:23:24 mhitch Exp $ */
2
3 /*
4 * Copyright (c) 1994 Christian E. Hopps
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Christian E. Hopps.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 #include "grfcc.h"
33 #if NGRFCC > 0
34 /*
35 * currently this is a backward compat hack that interface to
36 * view.c
37 */
38
39 #include "opt_uvm.h"
40
41 #include <sys/param.h>
42 #include <sys/proc.h>
43 #include <sys/errno.h>
44 #include <sys/ioctl.h>
45 #include <sys/queue.h>
46 #include <sys/device.h>
47 #include <sys/systm.h>
48 #include <vm/vm_param.h>
49 #include <machine/cpu.h>
50 #include <amiga/amiga/color.h> /* DEBUG */
51 #include <amiga/amiga/device.h>
52 #include <amiga/amiga/custom.h>
53 #include <amiga/amiga/cia.h>
54 #include <amiga/dev/grfioctl.h>
55 #include <amiga/dev/grfvar.h>
56 #include <amiga/dev/grf_ccreg.h>
57 #include <amiga/dev/grfabs_reg.h>
58 #include <amiga/dev/viewioctl.h>
59
60 #include <sys/conf.h>
61 #include <machine/conf.h>
62
63 #if defined(UVM)
64 #include <vm/vm.h>
65 #include <uvm/uvm_extern.h>
66 #endif
67
68 #include "view.h"
69
70 int grfccmatch __P((struct device *, struct cfdata *, void *));
71 int grfccprint __P((void *, const char *));
72 void grfccattach __P((struct device *, struct device *, void *));
73 void grf_cc_on __P((struct grf_softc *));
74
75 struct cfattach grfcc_ca = {
76 sizeof(struct grf_softc), grfccmatch, grfccattach
77 };
78
79 /*
80 * only used in console init
81 */
82 static struct cfdata *cfdata;
83
84 /*
85 * we make sure to only init things once. this is somewhat
86 * tricky regarding the console.
87 */
88 int
89 grfccmatch(pdp, cfp, auxp)
90 struct device *pdp;
91 struct cfdata *cfp;
92 void *auxp;
93 {
94 static int ccconunit = -1;
95 char *mainbus_name = auxp;
96
97 /*
98 * allow only one cc console
99 */
100 if (amiga_realconfig == 0 && ccconunit != -1)
101 return(0);
102 if (matchname("grfcc", mainbus_name) == 0)
103 return(0);
104 if (amiga_realconfig == 0 || ccconunit != cfp->cf_unit) {
105 if (grfcc_probe() == 0)
106 return(0);
107 viewprobe();
108 /*
109 * XXX nasty hack. opens view[0] and never closes.
110 */
111 if (viewopen(0, 0, 0, NULL))
112 return(0);
113 if (amiga_realconfig == 0) {
114 ccconunit = cfp->cf_unit;
115 cfdata = cfp;
116 }
117 }
118 return(1);
119 }
120
121 /*
122 * attach to the grfbus (mainbus)
123 */
124 void
125 grfccattach(pdp, dp, auxp)
126 struct device *pdp, *dp;
127 void *auxp;
128 {
129 static struct grf_softc congrf;
130 struct grf_softc *gp;
131
132 if (dp == NULL)
133 gp = &congrf;
134 else
135 gp = (struct grf_softc *)dp;
136
137 if (dp != NULL && congrf.g_regkva != 0) {
138 /*
139 * we inited earlier just copy the info
140 * take care not to copy the device struct though.
141 */
142 bcopy(&congrf.g_display, &gp->g_display,
143 (char *)&gp[1] - (char *)&gp->g_display);
144 } else {
145 gp->g_unit = GRF_CC_UNIT;
146 gp->g_flags = GF_ALIVE;
147 gp->g_mode = cc_mode;
148 gp->g_conpri = grfcc_cnprobe();
149 grfcc_iteinit(gp);
150 grf_cc_on(gp);
151 }
152 if (dp != NULL)
153 printf("\n");
154 /*
155 * attach grf
156 */
157 amiga_config_found(cfdata, &gp->g_device, gp, grfccprint);
158 }
159
160 int
161 grfccprint(auxp, pnp)
162 void *auxp;
163 const char *pnp;
164 {
165 if (pnp)
166 printf("grf%d at %s", ((struct grf_softc *)auxp)->g_unit,
167 pnp);
168 return(UNCONF);
169 }
170
171 /*
172 * Change the mode of the display.
173 * Right now all we can do is grfon/grfoff.
174 * Return a UNIX error number or 0 for success.
175 */
176 /*ARGSUSED*/
177 int
178 cc_mode(gp, cmd, arg, a2, a3)
179 struct grf_softc *gp;
180 u_long cmd;
181 void *arg;
182 u_long a2;
183 int a3;
184 {
185
186 switch (cmd) {
187 case GM_GRFON:
188 grf_cc_on(gp);
189 return(0);
190 case GM_GRFOFF:
191 viewioctl(0, VIOCREMOVE, NULL, -1, NULL);
192 return(0);
193 case GM_GRFCONFIG:
194 default:
195 break;
196 }
197 return(EINVAL);
198 }
199
200 void
201 grf_cc_on(gp)
202 struct grf_softc *gp;
203 {
204 struct view_size vs;
205 bmap_t bm;
206 struct grfinfo *gi;
207
208 gi = &gp->g_display;
209
210 viewioctl(0, VIOCGBMAP, (caddr_t)&bm, -1, NULL); /* XXX type of bm ? */
211
212 gp->g_data = (caddr_t) 0xDeadBeaf; /* not particularly clean.. */
213
214 gi->gd_regaddr = (caddr_t) 0xdff000; /* depricated */
215 gi->gd_regsize = round_page(sizeof (custom));
216 gi->gd_fbaddr = bm.hardware_address;
217 gi->gd_fbsize = bm.depth*bm.bytes_per_row*bm.rows;
218
219 if (viewioctl (0, VIOCGSIZE, (caddr_t)&vs, -1, NULL)) {
220 /* XXX type of vs ? */
221 /* fill in some default values... XXX */
222 vs.width = 640;
223 vs.height = 400;
224 vs.depth = 2;
225 }
226 gi->gd_colors = 1 << vs.depth;
227 gi->gd_planes = vs.depth;
228
229 gi->gd_fbwidth = vs.width;
230 gi->gd_fbheight = vs.height;
231 gi->gd_fbx = 0;
232 gi->gd_fby = 0;
233 gi->gd_dwidth = vs.width;
234 gi->gd_dheight = vs.height;
235 gi->gd_dx = 0;
236 gi->gd_dy = 0;
237
238 gp->g_regkva = (void *)0xDeadBeaf; /* builtin */
239 gp->g_fbkva = NULL; /* not needed, view internal */
240
241 viewioctl(0, VIOCDISPLAY, NULL, -1, NULL);
242 }
243 #endif
244
245