vga_isa.c revision 114384
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 * $FreeBSD: head/sys/isa/vga_isa.c 114384 2003-05-01 04:23:15Z peter $ 27 */ 28 29#include "opt_vga.h" 30#include "opt_fb.h" 31#include "opt_syscons.h" /* should be removed in the future, XXX */ 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/kernel.h> 36#include <sys/conf.h> 37#include <sys/bus.h> 38#include <sys/fbio.h> 39 40#include <machine/bus.h> 41#include <machine/resource.h> 42 43#include <sys/rman.h> 44 45#include <vm/vm.h> 46#include <vm/pmap.h> 47 48#include <machine/md_var.h> 49#ifdef __i386__ 50#include <machine/pc/bios.h> 51#endif 52 53#include <dev/fb/fbreg.h> 54#include <dev/fb/vgareg.h> 55 56#include <isa/isareg.h> 57#include <isa/isavar.h> 58 59#define VGA_SOFTC(unit) \ 60 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit)) 61 62static devclass_t isavga_devclass; 63 64#ifdef FB_INSTALL_CDEV 65 66static d_open_t isavga_open; 67static d_close_t isavga_close; 68static d_read_t isavga_read; 69static d_write_t isavga_write; 70static d_ioctl_t isavga_ioctl; 71static d_mmap_t isavga_mmap; 72 73static struct cdevsw isavga_cdevsw = { 74 .d_open = isavga_open, 75 .d_close = isavga_close, 76 .d_read = isavga_read, 77 .d_write = isavga_write, 78 .d_ioctl = isavga_ioctl, 79 .d_mmap = isavga_mmap, 80 .d_name = VGA_DRIVER_NAME, 81 .d_maj = -1, 82}; 83 84#endif /* FB_INSTALL_CDEV */ 85 86static void 87isavga_identify(driver_t *driver, device_t parent) 88{ 89 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0); 90} 91 92static int 93isavga_probe(device_t dev) 94{ 95 video_adapter_t adp; 96 device_t bus; 97 int error; 98 99 /* No pnp support */ 100 if (isa_get_vendorid(dev)) 101 return (ENXIO); 102 103 device_set_desc(dev, "Generic ISA VGA"); 104 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev)); 105 if (error == 0) { 106 bus = device_get_parent(dev); 107 bus_set_resource(dev, SYS_RES_IOPORT, 0, 108 adp.va_io_base, adp.va_io_size); 109 bus_set_resource(dev, SYS_RES_MEMORY, 0, 110 adp.va_mem_base, adp.va_mem_size); 111#if 0 112 isa_set_port(dev, adp.va_io_base); 113 isa_set_portsize(dev, adp.va_io_size); 114 isa_set_maddr(dev, adp.va_mem_base); 115 isa_set_msize(dev, adp.va_mem_size); 116#endif 117 } 118 return error; 119} 120 121static int 122isavga_attach(device_t dev) 123{ 124 vga_softc_t *sc; 125 struct resource *port; 126 struct resource *mem; 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 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 136 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 137 rid = 0; 138 mem = 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(makedev(0, VGA_MKMINOR(unit)), sc->adp, &isavga_cdevsw); 148 if (error) 149 return error; 150#endif /* FB_INSTALL_CDEV */ 151 152 if (bootverbose) 153 (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose); 154 155#if experimental 156 device_add_child(dev, "fb", -1); 157 bus_generic_attach(dev); 158#endif 159 160 return 0; 161} 162 163#ifdef FB_INSTALL_CDEV 164 165static int 166isavga_open(dev_t dev, int flag, int mode, struct thread *td) 167{ 168 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); 169} 170 171static int 172isavga_close(dev_t dev, int flag, int mode, struct thread *td) 173{ 174 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); 175} 176 177static int 178isavga_read(dev_t dev, struct uio *uio, int flag) 179{ 180 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 181} 182 183static int 184isavga_write(dev_t dev, struct uio *uio, int flag) 185{ 186 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 187} 188 189static int 190isavga_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td) 191{ 192 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td); 193} 194 195static int 196isavga_mmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int prot) 197{ 198 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot); 199} 200 201#endif /* FB_INSTALL_CDEV */ 202 203static device_method_t isavga_methods[] = { 204 DEVMETHOD(device_identify, isavga_identify), 205 DEVMETHOD(device_probe, isavga_probe), 206 DEVMETHOD(device_attach, isavga_attach), 207 208 DEVMETHOD(bus_print_child, bus_generic_print_child), 209 { 0, 0 } 210}; 211 212static driver_t isavga_driver = { 213 VGA_DRIVER_NAME, 214 isavga_methods, 215 sizeof(vga_softc_t), 216}; 217 218DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0); 219