vga_isa.c revision 51052
1271294Sngie/*- 2271294Sngie * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 3271294Sngie * All rights reserved. 4271294Sngie * 5271294Sngie * Redistribution and use in source and binary forms, with or without 6271294Sngie * modification, are permitted provided that the following conditions 7271294Sngie * are met: 8271294Sngie * 1. Redistributions of source code must retain the above copyright 9271294Sngie * notice, this list of conditions and the following disclaimer as 10271294Sngie * the first lines of this file unmodified. 11271294Sngie * 2. Redistributions in binary form must reproduce the above copyright 12271294Sngie * notice, this list of conditions and the following disclaimer in the 13271294Sngie * documentation and/or other materials provided with the distribution. 14271294Sngie * 15271294Sngie * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 16271294Sngie * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17271294Sngie * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18271294Sngie * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19271294Sngie * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20271294Sngie * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21271294Sngie * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22271294Sngie * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23271294Sngie * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24271294Sngie * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25271294Sngie * 26271294Sngie * $FreeBSD: head/sys/isa/vga_isa.c 51052 1999-09-07 08:42:49Z dfr $ 27 */ 28 29#include "vga.h" 30#include "opt_vga.h" 31#include "opt_fb.h" 32#include "opt_syscons.h" /* should be removed in the future, XXX */ 33 34#if NVGA > 0 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/kernel.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#include <machine/pc/bios.h> 53 54#include <dev/fb/fbreg.h> 55#include <dev/fb/vgareg.h> 56 57#include <isa/isareg.h> 58#include <isa/isavar.h> 59 60#define VGA_SOFTC(unit) \ 61 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit)) 62 63static devclass_t isavga_devclass; 64 65static int isavga_probe(device_t dev); 66static int isavga_attach(device_t dev); 67 68static device_method_t isavga_methods[] = { 69 DEVMETHOD(device_probe, isavga_probe), 70 DEVMETHOD(device_attach, isavga_attach), 71 72 DEVMETHOD(bus_print_child, bus_generic_print_child), 73 { 0, 0 } 74}; 75 76static driver_t isavga_driver = { 77 VGA_DRIVER_NAME, 78 isavga_methods, 79 sizeof(vga_softc_t), 80}; 81 82DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0); 83 84#ifdef FB_INSTALL_CDEV 85 86static d_open_t isavga_open; 87static d_close_t isavga_close; 88static d_read_t isavga_read; 89static d_write_t isavga_write; 90static d_ioctl_t isavga_ioctl; 91static d_mmap_t isavga_mmap; 92 93static struct cdevsw isavga_cdevsw = { 94 /* open */ isavga_open, 95 /* close */ isavga_close, 96 /* read */ isavga_read, 97 /* write */ isavga_write, 98 /* ioctl */ isavga_ioctl, 99 /* stop */ nostop, 100 /* reset */ noreset, 101 /* devtotty */ nodevtotty, 102 /* poll */ nopoll, 103 /* mmap */ isavga_mmap, 104 /* strategy */ nostrategy, 105 /* name */ VGA_DRIVER_NAME, 106 /* parms */ noparms, 107 /* maj */ -1, 108 /* dump */ nodump, 109 /* psize */ nopsize, 110 /* flags */ 0, 111 /* maxio */ 0, 112 /* bmaj */ -1 113}; 114 115#endif /* FB_INSTALL_CDEV */ 116 117static int 118isavga_probe(device_t dev) 119{ 120 video_adapter_t adp; 121 device_t bus; 122 int error; 123 124 /* No pnp support */ 125 if (isa_get_vendorid(dev)) 126 return (ENXIO); 127 128 device_set_desc(dev, "Generic ISA VGA"); 129 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev)); 130 if (error == 0) { 131 bus = device_get_parent(dev); 132 ISA_SET_RESOURCE(bus, dev, SYS_RES_IOPORT, 0, 133 adp.va_io_base, adp.va_io_size); 134 ISA_SET_RESOURCE(bus, dev, SYS_RES_MEMORY, 0, 135 adp.va_mem_base, adp.va_mem_size); 136#if 0 137 isa_set_port(dev, adp.va_io_base); 138 isa_set_portsize(dev, adp.va_io_size); 139 isa_set_maddr(dev, adp.va_mem_base); 140 isa_set_msize(dev, adp.va_mem_size); 141#endif 142 } 143 return error; 144} 145 146static int 147isavga_attach(device_t dev) 148{ 149 vga_softc_t *sc; 150 struct resource *port; 151 struct resource *mem; 152 int unit; 153 int rid; 154 int error; 155 156 unit = device_get_unit(dev); 157 sc = device_get_softc(dev); 158 159 rid = 0; 160 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 161 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 162 rid = 0; 163 mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 164 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 165 166 error = vga_attach_unit(unit, sc, device_get_flags(dev)); 167 if (error) 168 return error; 169 170#ifdef FB_INSTALL_CDEV 171 /* attach a virtual frame buffer device */ 172 error = fb_attach(makedev(0, VGA_MKMINOR(unit)), sc->adp, &isavga_cdevsw); 173 if (error) 174 return error; 175#endif /* FB_INSTALL_CDEV */ 176 177 if (bootverbose) 178 (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose); 179 180#if experimental 181 device_add_child(dev, "fb", -1, NULL); 182 bus_generic_attach(dev); 183#endif 184 185 return 0; 186} 187 188#ifdef FB_INSTALL_CDEV 189 190static int 191isavga_open(dev_t dev, int flag, int mode, struct proc *p) 192{ 193 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, p); 194} 195 196static int 197isavga_close(dev_t dev, int flag, int mode, struct proc *p) 198{ 199 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, p); 200} 201 202static int 203isavga_read(dev_t dev, struct uio *uio, int flag) 204{ 205 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 206} 207 208static int 209isavga_write(dev_t dev, struct uio *uio, int flag) 210{ 211 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 212} 213 214static int 215isavga_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p) 216{ 217 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, p); 218} 219 220static int 221isavga_mmap(dev_t dev, vm_offset_t offset, int prot) 222{ 223 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, prot); 224} 225 226#endif /* FB_INSTALL_CDEV */ 227 228#endif /* NVGA > 0 */ 229