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