1 /* 2 * Copyright (c) 1988 University of Utah. 3 * Copyright (c) 1990 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * the Systems Programming Group of the University of Utah Computer 8 * Science Department. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * from: Utah $Hdr: grf.c 1.31 91/01/21$ 39 * 40 * @(#)grf.c 7.8 (Berkeley) 5/7/91 41 * $Id: grf.c,v 1.14 1994/06/16 14:28:47 chopps Exp $ 42 */ 43 44 /* 45 * Graphics display driver for the Amiga 46 * This is the hardware-independent portion of the driver. 47 * Hardware access is through the grf_softc->g_mode routine. 48 */ 49 50 #include <sys/param.h> 51 #include <sys/proc.h> 52 #include <sys/ioctl.h> 53 #include <sys/device.h> 54 #include <sys/file.h> 55 #include <sys/malloc.h> 56 #include <sys/conf.h> 57 #include <sys/systm.h> 58 #include <sys/vnode.h> 59 #include <sys/mman.h> 60 #include <vm/vm.h> 61 #include <vm/vm_kern.h> 62 #include <vm/vm_page.h> 63 #include <vm/vm_pager.h> 64 #include <machine/cpu.h> 65 #include <amiga/amiga/color.h> /* DEBUG */ 66 #include <amiga/amiga/device.h> 67 #include <amiga/dev/grfioctl.h> 68 #include <amiga/dev/grfvar.h> 69 #include <amiga/dev/itevar.h> 70 71 #include "grf.h" 72 #if NGRF > 0 73 74 #include "ite.h" 75 #if NITE == 0 76 #define ite_on(u,f) 77 #define ite_off(u,f) 78 #define ite_reinit(d) 79 #endif 80 81 int grfopen __P((dev_t, int, int, struct proc *)); 82 int grfclose __P((dev_t, int)); 83 int grfioctl __P((dev_t, int, caddr_t, int, struct proc *)); 84 int grfselect __P((dev_t, int)); 85 int grfmap __P((dev_t, int, int)); 86 87 int grfon __P((dev_t)); 88 int grfoff __P((dev_t)); 89 int grfsinfo __P((dev_t, struct grfdyninfo *)); 90 #ifdef BANKEDDEVPAGER 91 int grfbanked_get __P((dev_t, off_t, int)); 92 int grfbanked_cur __P((dev_t)); 93 int grfbanked_set __P((dev_t, int)); 94 #endif 95 96 void grfattach __P((struct device *, struct device *, void *)); 97 int grfmatch __P((struct device *, struct cfdata *, void *)); 98 int grfprint __P((void *, char *)); 99 /* 100 * pointers to grf drivers device structs 101 */ 102 struct grf_softc *grfsp[NGRF]; 103 104 105 struct cfdriver grfcd = { 106 NULL, "grf", grfmatch, grfattach, DV_DULL, 107 sizeof(struct device), NULL, 0 }; 108 109 /* 110 * only used in console init. 111 */ 112 static struct cfdata *cfdata; 113 114 /* 115 * match if the unit of grf matches its perspective 116 * low level board driver. 117 */ 118 int 119 grfmatch(pdp, cfp, auxp) 120 struct device *pdp; 121 struct cfdata *cfp; 122 void *auxp; 123 { 124 if (cfp->cf_unit != ((struct grf_softc *)pdp)->g_unit) 125 return(0); 126 cfdata = cfp; 127 return(1); 128 } 129 130 /* 131 * attach.. plug pointer in and print some info. 132 * then try and attach an ite to us. note: dp is NULL 133 * durring console init. 134 */ 135 void 136 grfattach(pdp, dp, auxp) 137 struct device *pdp, *dp; 138 void *auxp; 139 { 140 struct grf_softc *gp; 141 int maj; 142 143 gp = (struct grf_softc *)pdp; 144 grfsp[gp->g_unit] = (struct grf_softc *)pdp; 145 146 /* 147 * find our major device number 148 */ 149 for(maj = 0; maj < nchrdev; maj++) 150 if (cdevsw[maj].d_open == grfopen) 151 break; 152 153 gp->g_grfdev = makedev(maj, gp->g_unit); 154 if (dp != NULL) { 155 printf(": width %d height %d", gp->g_display.gd_dwidth, 156 gp->g_display.gd_dheight); 157 if (gp->g_display.gd_colors == 2) 158 printf(" monochrome\n"); 159 else 160 printf(" colors %d\n", gp->g_display.gd_colors); 161 } 162 163 /* 164 * try and attach an ite 165 */ 166 amiga_config_found(cfdata, dp, gp, grfprint); 167 } 168 169 int 170 grfprint(auxp, pnp) 171 void *auxp; 172 char *pnp; 173 { 174 if (pnp) 175 printf("ite at %s", pnp); 176 return(UNCONF); 177 } 178 179 /*ARGSUSED*/ 180 int 181 grfopen(dev, flags, devtype, p) 182 dev_t dev; 183 int flags, devtype; 184 struct proc *p; 185 { 186 struct grf_softc *gp; 187 188 if (GRFUNIT(dev) >= NGRF) 189 return(ENXIO); 190 191 gp = grfsp[GRFUNIT(dev)]; 192 193 if ((gp->g_flags & GF_ALIVE) == 0) 194 return(ENXIO); 195 196 if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE)) 197 return(EBUSY); 198 199 return(0); 200 } 201 202 /*ARGSUSED*/ 203 int 204 grfclose(dev, flags) 205 dev_t dev; 206 int flags; 207 { 208 struct grf_softc *gp; 209 210 gp = grfsp[GRFUNIT(dev)]; 211 (void)grfoff(dev); 212 gp->g_flags &= GF_ALIVE; 213 return(0); 214 } 215 216 /*ARGSUSED*/ 217 int 218 grfioctl(dev, cmd, data, flag, p) 219 dev_t dev; 220 int cmd, flag; 221 caddr_t data; 222 struct proc *p; 223 { 224 struct grf_softc *gp; 225 int error; 226 227 gp = grfsp[GRFUNIT(dev)]; 228 error = 0; 229 230 switch (cmd) { 231 case OGRFIOCGINFO: 232 /* argl.. no bank-member.. */ 233 bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo)-4); 234 break; 235 case GRFIOCGINFO: 236 bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo)); 237 break; 238 case GRFIOCON: 239 error = grfon(dev); 240 break; 241 case GRFIOCOFF: 242 error = grfoff(dev); 243 break; 244 case GRFIOCSINFO: 245 error = grfsinfo(dev, (struct grfdyninfo *) data); 246 break; 247 case GRFGETVMODE: 248 return(gp->g_mode(gp, GM_GRFGETVMODE, data)); 249 case GRFSETVMODE: 250 error = gp->g_mode(gp, GM_GRFSETVMODE, data); 251 if (error == 0 && gp->g_itedev) 252 ite_reinit(gp->g_itedev); 253 break; 254 case GRFGETNUMVM: 255 return(gp->g_mode(gp, GM_GRFGETNUMVM, data)); 256 /* 257 * these are all hardware dependant, and have to be resolved 258 * in the respective driver. 259 */ 260 case GRFIOCPUTCMAP: 261 case GRFIOCGETCMAP: 262 case GRFIOCSSPRITEPOS: 263 case GRFIOCGSPRITEPOS: 264 case GRFIOCSSPRITEINF: 265 case GRFIOCGSPRITEINF: 266 case GRFIOCGSPRITEMAX: 267 return(gp->g_mode(gp, GM_GRFIOCTL, cmd, data)); 268 default: 269 /* 270 * check to see whether it's a command recognized by the 271 * view code if the unit is 0 272 * XXX 273 */ 274 if (GRFUNIT(dev) == 0) 275 return(viewioctl(dev, cmd, data, flag, p)); 276 error = EINVAL; 277 break; 278 279 } 280 return(error); 281 } 282 283 /*ARGSUSED*/ 284 int 285 grfselect(dev, rw) 286 dev_t dev; 287 int rw; 288 { 289 if (rw == FREAD) 290 return(0); 291 return(1); 292 } 293 294 /* 295 * map the contents of a graphics display card into process' 296 * memory space. 297 */ 298 int 299 grfmap(dev, off, prot) 300 dev_t dev; 301 int off, prot; 302 { 303 struct grf_softc *gp; 304 struct grfinfo *gi; 305 306 gp = grfsp[GRFUNIT(dev)]; 307 gi = &gp->g_display; 308 309 /* 310 * control registers 311 */ 312 if (off >= 0 && off < gi->gd_regsize) 313 return(((u_int)gi->gd_regaddr + off) >> PGSHIFT); 314 315 /* 316 * frame buffer 317 */ 318 if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) { 319 off -= gi->gd_regsize; 320 #ifdef BANKEDDEVPAGER 321 if (gi->gd_bank_size) 322 off %= gi->gd_bank_size; 323 #endif 324 return(((u_int)gi->gd_fbaddr + off) >> PGSHIFT); 325 } 326 /* bogus */ 327 return(-1); 328 } 329 330 int 331 grfon(dev) 332 dev_t dev; 333 { 334 struct grf_softc *gp; 335 336 gp = grfsp[GRFUNIT(dev)]; 337 338 if (gp->g_flags & GF_GRFON) 339 return(0); 340 341 gp->g_flags |= GF_GRFON; 342 if (gp->g_itedev != NODEV) 343 ite_off(gp->g_itedev, 3); 344 345 return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON)); 346 } 347 348 int 349 grfoff(dev) 350 dev_t dev; 351 { 352 struct grf_softc *gp; 353 int error; 354 355 gp = grfsp[GRFUNIT(dev)]; 356 357 if ((gp->g_flags & GF_GRFON) == 0) 358 return(0); 359 360 gp->g_flags &= ~GF_GRFON; 361 error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF); 362 363 /* 364 * Closely tied together no X's 365 */ 366 if (gp->g_itedev != NODEV) 367 ite_on(gp->g_itedev, 2); 368 369 return(error); 370 } 371 372 int 373 grfsinfo(dev, dyninfo) 374 dev_t dev; 375 struct grfdyninfo *dyninfo; 376 { 377 struct grf_softc *gp; 378 int error; 379 380 gp = grfsp[GRFUNIT(dev)]; 381 error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo); 382 383 /* 384 * Closely tied together no X's 385 */ 386 if (gp->g_itedev != NODEV) 387 ite_reinit(gp->g_itedev); 388 return(error); 389 } 390 391 #ifdef BANKEDDEVPAGER 392 393 int 394 grfbanked_get (dev, off, prot) 395 dev_t dev; 396 off_t off; 397 int prot; 398 { 399 struct grf_softc *gp; 400 struct grfinfo *gi; 401 int error, bank; 402 403 gp = grfsp[GRFUNIT(dev)]; 404 gi = &gp->g_display; 405 406 off -= gi->gd_regsize; 407 if (off < 0 || off >= gi->gd_fbsize) 408 return -1; 409 410 error = gp->g_mode(gp, GM_GRFGETBANK, &bank, off, prot); 411 return error ? -1 : bank; 412 } 413 414 int 415 grfbanked_cur (dev) 416 dev_t dev; 417 { 418 struct grf_softc *gp; 419 int error, bank; 420 421 gp = grfsp[GRFUNIT(dev)]; 422 423 error = gp->g_mode(gp, GM_GRFGETCURBANK, &bank); 424 return(error ? -1 : bank); 425 } 426 427 int 428 grfbanked_set (dev, bank) 429 dev_t dev; 430 int bank; 431 { 432 struct grf_softc *gp; 433 434 gp = grfsp[GRFUNIT(dev)]; 435 return(gp->g_mode(gp, GM_GRFSETBANK, bank) ? -1 : 0); 436 } 437 438 #endif /* BANKEDDEVPAGER */ 439 #endif /* NGRF > 0 */ 440