1/*- 2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer as 10 * the first lines of this file unmodified. 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer as 10 * the first lines of this file unmodified. 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h>
|
28__FBSDID("$FreeBSD: head/sys/isa/vga_isa.c 174985 2007-12-29 23:26:59Z wkoszek $");
| 28__FBSDID("$FreeBSD: head/sys/isa/vga_isa.c 198866 2009-11-04 00:58:20Z jkim $");
|
29 30#include "opt_vga.h" 31#include "opt_fb.h" 32#include "opt_syscons.h" /* should be removed in the future, XXX */ 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/module.h> 39#include <sys/conf.h> 40#include <sys/bus.h> 41#include <sys/fbio.h> 42 43#include <machine/bus.h> 44#include <machine/resource.h> 45 46#include <sys/rman.h> 47 48#include <vm/vm.h> 49#include <vm/pmap.h> 50 51#include <machine/md_var.h> 52#ifdef __i386__ 53#include <machine/pc/bios.h> 54#endif 55 56#include <dev/fb/fbreg.h> 57#include <dev/fb/vgareg.h> 58 59#include <isa/isareg.h> 60#include <isa/isavar.h> 61 62#define VGA_SOFTC(unit) \ 63 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit)) 64 65static devclass_t isavga_devclass; 66 67#ifdef FB_INSTALL_CDEV 68 69static d_open_t isavga_open; 70static d_close_t isavga_close; 71static d_read_t isavga_read; 72static d_write_t isavga_write; 73static d_ioctl_t isavga_ioctl; 74static d_mmap_t isavga_mmap; 75 76static struct cdevsw isavga_cdevsw = { 77 .d_version = D_VERSION, 78 .d_flags = D_NEEDGIANT, 79 .d_open = isavga_open, 80 .d_close = isavga_close, 81 .d_read = isavga_read, 82 .d_write = isavga_write, 83 .d_ioctl = isavga_ioctl, 84 .d_mmap = isavga_mmap, 85 .d_name = VGA_DRIVER_NAME, 86}; 87 88#endif /* FB_INSTALL_CDEV */ 89 90static void 91isavga_identify(driver_t *driver, device_t parent) 92{ 93 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0); 94} 95 96static int 97isavga_probe(device_t dev) 98{ 99 video_adapter_t adp; 100 int error; 101 102 /* No pnp support */ 103 if (isa_get_vendorid(dev)) 104 return (ENXIO); 105 106 device_set_desc(dev, "Generic ISA VGA"); 107 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev)); 108 if (error == 0) { 109 bus_set_resource(dev, SYS_RES_IOPORT, 0, 110 adp.va_io_base, adp.va_io_size); 111 bus_set_resource(dev, SYS_RES_MEMORY, 0, 112 adp.va_mem_base, adp.va_mem_size); 113#if 0 114 isa_set_port(dev, adp.va_io_base); 115 isa_set_portsize(dev, adp.va_io_size); 116 isa_set_maddr(dev, adp.va_mem_base); 117 isa_set_msize(dev, adp.va_mem_size); 118#endif 119 } 120 return error; 121} 122 123static int 124isavga_attach(device_t dev) 125{ 126 vga_softc_t *sc; 127 int unit; 128 int rid; 129 int error; 130 131 unit = device_get_unit(dev); 132 sc = device_get_softc(dev); 133 134 rid = 0; 135 bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 136 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 137 rid = 0; 138 bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 139 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 140 141 error = vga_attach_unit(unit, sc, device_get_flags(dev)); 142 if (error) 143 return error; 144 145#ifdef FB_INSTALL_CDEV 146 /* attach a virtual frame buffer device */ 147 error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw); 148 if (error) 149 return error; 150#endif /* FB_INSTALL_CDEV */ 151 152 if (0 && bootverbose) 153 vidd_diag(sc->adp, bootverbose); 154 155#if 0 /* experimental */ 156 device_add_child(dev, "fb", -1); 157 bus_generic_attach(dev); 158#endif 159 160 return 0; 161} 162 163static int 164isavga_suspend(device_t dev) 165{ 166 vga_softc_t *sc; 167 int err, nbytes; 168 169 sc = device_get_softc(dev); 170 err = bus_generic_suspend(dev); 171 if (err) 172 return (err); 173 174 /* Save the video state across the suspend. */ 175 if (sc->state_buf != NULL) { 176 free(sc->state_buf, M_TEMP); 177 sc->state_buf = NULL; 178 } 179 nbytes = vidd_save_state(sc->adp, NULL, 0); 180 if (nbytes <= 0) 181 return (0);
| 29 30#include "opt_vga.h" 31#include "opt_fb.h" 32#include "opt_syscons.h" /* should be removed in the future, XXX */ 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/module.h> 39#include <sys/conf.h> 40#include <sys/bus.h> 41#include <sys/fbio.h> 42 43#include <machine/bus.h> 44#include <machine/resource.h> 45 46#include <sys/rman.h> 47 48#include <vm/vm.h> 49#include <vm/pmap.h> 50 51#include <machine/md_var.h> 52#ifdef __i386__ 53#include <machine/pc/bios.h> 54#endif 55 56#include <dev/fb/fbreg.h> 57#include <dev/fb/vgareg.h> 58 59#include <isa/isareg.h> 60#include <isa/isavar.h> 61 62#define VGA_SOFTC(unit) \ 63 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit)) 64 65static devclass_t isavga_devclass; 66 67#ifdef FB_INSTALL_CDEV 68 69static d_open_t isavga_open; 70static d_close_t isavga_close; 71static d_read_t isavga_read; 72static d_write_t isavga_write; 73static d_ioctl_t isavga_ioctl; 74static d_mmap_t isavga_mmap; 75 76static struct cdevsw isavga_cdevsw = { 77 .d_version = D_VERSION, 78 .d_flags = D_NEEDGIANT, 79 .d_open = isavga_open, 80 .d_close = isavga_close, 81 .d_read = isavga_read, 82 .d_write = isavga_write, 83 .d_ioctl = isavga_ioctl, 84 .d_mmap = isavga_mmap, 85 .d_name = VGA_DRIVER_NAME, 86}; 87 88#endif /* FB_INSTALL_CDEV */ 89 90static void 91isavga_identify(driver_t *driver, device_t parent) 92{ 93 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0); 94} 95 96static int 97isavga_probe(device_t dev) 98{ 99 video_adapter_t adp; 100 int error; 101 102 /* No pnp support */ 103 if (isa_get_vendorid(dev)) 104 return (ENXIO); 105 106 device_set_desc(dev, "Generic ISA VGA"); 107 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev)); 108 if (error == 0) { 109 bus_set_resource(dev, SYS_RES_IOPORT, 0, 110 adp.va_io_base, adp.va_io_size); 111 bus_set_resource(dev, SYS_RES_MEMORY, 0, 112 adp.va_mem_base, adp.va_mem_size); 113#if 0 114 isa_set_port(dev, adp.va_io_base); 115 isa_set_portsize(dev, adp.va_io_size); 116 isa_set_maddr(dev, adp.va_mem_base); 117 isa_set_msize(dev, adp.va_mem_size); 118#endif 119 } 120 return error; 121} 122 123static int 124isavga_attach(device_t dev) 125{ 126 vga_softc_t *sc; 127 int unit; 128 int rid; 129 int error; 130 131 unit = device_get_unit(dev); 132 sc = device_get_softc(dev); 133 134 rid = 0; 135 bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 136 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 137 rid = 0; 138 bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 139 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 140 141 error = vga_attach_unit(unit, sc, device_get_flags(dev)); 142 if (error) 143 return error; 144 145#ifdef FB_INSTALL_CDEV 146 /* attach a virtual frame buffer device */ 147 error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw); 148 if (error) 149 return error; 150#endif /* FB_INSTALL_CDEV */ 151 152 if (0 && bootverbose) 153 vidd_diag(sc->adp, bootverbose); 154 155#if 0 /* experimental */ 156 device_add_child(dev, "fb", -1); 157 bus_generic_attach(dev); 158#endif 159 160 return 0; 161} 162 163static int 164isavga_suspend(device_t dev) 165{ 166 vga_softc_t *sc; 167 int err, nbytes; 168 169 sc = device_get_softc(dev); 170 err = bus_generic_suspend(dev); 171 if (err) 172 return (err); 173 174 /* Save the video state across the suspend. */ 175 if (sc->state_buf != NULL) { 176 free(sc->state_buf, M_TEMP); 177 sc->state_buf = NULL; 178 } 179 nbytes = vidd_save_state(sc->adp, NULL, 0); 180 if (nbytes <= 0) 181 return (0);
|
182 sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT | M_ZERO); 183 if (sc->state_buf == NULL) 184 return (0); 185 if (bootverbose) 186 device_printf(dev, "saving %d bytes of video state\n", nbytes); 187 if (vidd_save_state(sc->adp, sc->state_buf, nbytes) != 0) { 188 device_printf(dev, "failed to save state (nbytes=%d)\n", 189 nbytes); 190 free(sc->state_buf, M_TEMP); 191 sc->state_buf = NULL;
| 182 sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT); 183 if (sc->state_buf != NULL) { 184 if (bootverbose) 185 device_printf(dev, "saving %d bytes of video state\n", 186 nbytes); 187 if (vidd_save_state(sc->adp, sc->state_buf, nbytes) != 0) { 188 device_printf(dev, "failed to save state (nbytes=%d)\n", 189 nbytes); 190 free(sc->state_buf, M_TEMP); 191 sc->state_buf = NULL; 192 }
|
192 }
| 193 }
|
| 194 195 /* Save the color palette across the suspend. */ 196 if (sc->pal_buf != NULL) 197 free(sc->pal_buf, M_TEMP); 198 sc->pal_buf = malloc(256 * 3, M_TEMP, M_NOWAIT); 199 if (sc->pal_buf != NULL) { 200 if (bootverbose) 201 device_printf(dev, "saving color palette\n"); 202 if (vidd_save_palette(sc->adp, sc->pal_buf) != 0) { 203 device_printf(dev, "failed to save palette\n"); 204 free(sc->pal_buf, M_TEMP); 205 sc->pal_buf = NULL; 206 } 207 } 208
|
193 return (0); 194} 195 196static int 197isavga_resume(device_t dev) 198{ 199 vga_softc_t *sc; 200 201 sc = device_get_softc(dev); 202 if (sc->state_buf != NULL) { 203 if (vidd_load_state(sc->adp, sc->state_buf) != 0) 204 device_printf(dev, "failed to reload state\n"); 205 free(sc->state_buf, M_TEMP); 206 sc->state_buf = NULL; 207 }
| 209 return (0); 210} 211 212static int 213isavga_resume(device_t dev) 214{ 215 vga_softc_t *sc; 216 217 sc = device_get_softc(dev); 218 if (sc->state_buf != NULL) { 219 if (vidd_load_state(sc->adp, sc->state_buf) != 0) 220 device_printf(dev, "failed to reload state\n"); 221 free(sc->state_buf, M_TEMP); 222 sc->state_buf = NULL; 223 }
|
| 224 if (sc->pal_buf != NULL) { 225 if (vidd_load_palette(sc->adp, sc->pal_buf) != 0) 226 device_printf(dev, "failed to reload palette\n"); 227 free(sc->pal_buf, M_TEMP); 228 sc->pal_buf = NULL; 229 }
|
208 209 bus_generic_resume(dev); 210 return 0; 211} 212 213#ifdef FB_INSTALL_CDEV 214 215static int 216isavga_open(struct cdev *dev, int flag, int mode, struct thread *td) 217{ 218 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); 219} 220 221static int 222isavga_close(struct cdev *dev, int flag, int mode, struct thread *td) 223{ 224 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); 225} 226 227static int 228isavga_read(struct cdev *dev, struct uio *uio, int flag) 229{ 230 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 231} 232 233static int 234isavga_write(struct cdev *dev, struct uio *uio, int flag) 235{ 236 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 237} 238 239static int 240isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td) 241{ 242 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td); 243} 244 245static int 246isavga_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot) 247{ 248 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot); 249} 250 251#endif /* FB_INSTALL_CDEV */ 252 253static device_method_t isavga_methods[] = { 254 DEVMETHOD(device_identify, isavga_identify), 255 DEVMETHOD(device_probe, isavga_probe), 256 DEVMETHOD(device_attach, isavga_attach), 257 DEVMETHOD(device_suspend, isavga_suspend), 258 DEVMETHOD(device_resume, isavga_resume), 259 260 DEVMETHOD(bus_print_child, bus_generic_print_child), 261 { 0, 0 } 262}; 263 264static driver_t isavga_driver = { 265 VGA_DRIVER_NAME, 266 isavga_methods, 267 sizeof(vga_softc_t), 268}; 269 270DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);
| 230 231 bus_generic_resume(dev); 232 return 0; 233} 234 235#ifdef FB_INSTALL_CDEV 236 237static int 238isavga_open(struct cdev *dev, int flag, int mode, struct thread *td) 239{ 240 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); 241} 242 243static int 244isavga_close(struct cdev *dev, int flag, int mode, struct thread *td) 245{ 246 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); 247} 248 249static int 250isavga_read(struct cdev *dev, struct uio *uio, int flag) 251{ 252 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 253} 254 255static int 256isavga_write(struct cdev *dev, struct uio *uio, int flag) 257{ 258 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 259} 260 261static int 262isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td) 263{ 264 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td); 265} 266 267static int 268isavga_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot) 269{ 270 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot); 271} 272 273#endif /* FB_INSTALL_CDEV */ 274 275static device_method_t isavga_methods[] = { 276 DEVMETHOD(device_identify, isavga_identify), 277 DEVMETHOD(device_probe, isavga_probe), 278 DEVMETHOD(device_attach, isavga_attach), 279 DEVMETHOD(device_suspend, isavga_suspend), 280 DEVMETHOD(device_resume, isavga_resume), 281 282 DEVMETHOD(bus_print_child, bus_generic_print_child), 283 { 0, 0 } 284}; 285 286static driver_t isavga_driver = { 287 VGA_DRIVER_NAME, 288 isavga_methods, 289 sizeof(vga_softc_t), 290}; 291 292DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);
|