vga_isa.c revision 114384
1163516Simp/*- 2163516Simp * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 3163516Simp * All rights reserved. 4163516Simp * 5163516Simp * Redistribution and use in source and binary forms, with or without 6163516Simp * modification, are permitted provided that the following conditions 7163516Simp * are met: 8163516Simp * 1. Redistributions of source code must retain the above copyright 9163516Simp * notice, this list of conditions and the following disclaimer as 10163516Simp * the first lines of this file unmodified. 11163516Simp * 2. Redistributions in binary form must reproduce the above copyright 12163516Simp * notice, this list of conditions and the following disclaimer in the 13163516Simp * documentation and/or other materials provided with the distribution. 14163516Simp * 15163516Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 16163516Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17163516Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18163516Simp * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19163516Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20163516Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21163516Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22163516Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23163516Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24170002Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25170002Simp * 26170002Simp * $FreeBSD: head/sys/isa/vga_isa.c 114384 2003-05-01 04:23:15Z peter $ 27170002Simp */ 28170002Simp 29170002Simp#include "opt_vga.h" 30170002Simp#include "opt_fb.h" 31170002Simp#include "opt_syscons.h" /* should be removed in the future, XXX */ 32170002Simp 33170002Simp#include <sys/param.h> 34170002Simp#include <sys/systm.h> 35170002Simp#include <sys/kernel.h> 36170002Simp#include <sys/conf.h> 37170002Simp#include <sys/bus.h> 38170002Simp#include <sys/fbio.h> 39170002Simp 40170002Simp#include <machine/bus.h> 41170002Simp#include <machine/resource.h> 42170002Simp 43170002Simp#include <sys/rman.h> 44170002Simp 45170002Simp#include <vm/vm.h> 46170002Simp#include <vm/pmap.h> 47170002Simp 48170002Simp#include <machine/md_var.h> 49170002Simp#ifdef __i386__ 50170002Simp#include <machine/pc/bios.h> 51163516Simp#endif 52163516Simp 53163516Simp#include <dev/fb/fbreg.h> 54163516Simp#include <dev/fb/vgareg.h> 55163516Simp 56163516Simp#include <isa/isareg.h> 57163516Simp#include <isa/isavar.h> 58163516Simp 59163516Simp#define VGA_SOFTC(unit) \ 60163516Simp ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit)) 61163516Simp 62163516Simpstatic devclass_t isavga_devclass; 63163516Simp 64183704Smav#ifdef FB_INSTALL_CDEV 65187875Smav 66163516Simpstatic d_open_t isavga_open; 67163516Simpstatic d_close_t isavga_close; 68163516Simpstatic d_read_t isavga_read; 69163516Simpstatic d_write_t isavga_write; 70163516Simpstatic d_ioctl_t isavga_ioctl; 71163516Simpstatic d_mmap_t isavga_mmap; 72163516Simp 73163516Simpstatic struct cdevsw isavga_cdevsw = { 74163516Simp .d_open = isavga_open, 75163516Simp .d_close = isavga_close, 76163516Simp .d_read = isavga_read, 77163516Simp .d_write = isavga_write, 78163516Simp .d_ioctl = isavga_ioctl, 79163516Simp .d_mmap = isavga_mmap, 80163516Simp .d_name = VGA_DRIVER_NAME, 81163516Simp .d_maj = -1, 82163516Simp}; 83163516Simp 84163516Simp#endif /* FB_INSTALL_CDEV */ 85163516Simp 86163516Simpstatic void 87183704Smavisavga_identify(driver_t *driver, device_t parent) 88183704Smav{ 89184033Smav BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0); 90163516Simp} 91163516Simp 92163516Simpstatic int 93163516Simpisavga_probe(device_t dev) 94183704Smav{ 95184033Smav video_adapter_t adp; 96183447Simp device_t bus; 97183704Smav int error; 98183704Smav 99183731Smav /* No pnp support */ 100183731Smav if (isa_get_vendorid(dev)) 101183704Smav return (ENXIO); 102183704Smav 103184033Smav device_set_desc(dev, "Generic ISA VGA"); 104236089Smarius error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev)); 105163516Simp if (error == 0) { 106163516Simp bus = device_get_parent(dev); 107163516Simp bus_set_resource(dev, SYS_RES_IOPORT, 0, 108163516Simp adp.va_io_base, adp.va_io_size); 109248085Smarius bus_set_resource(dev, SYS_RES_MEMORY, 0, 110187875Smav adp.va_mem_base, adp.va_mem_size); 111188044Simp#if 0 112187875Smav isa_set_port(dev, adp.va_io_base); 113187875Smav isa_set_portsize(dev, adp.va_io_size); 114163516Simp isa_set_maddr(dev, adp.va_mem_base); 115236642Smarius isa_set_msize(dev, adp.va_mem_size); 116163516Simp#endif 117236642Smarius } 118236642Smarius return error; 119163516Simp} 120236642Smarius 121236642Smariusstatic int 122236642Smariusisavga_attach(device_t dev) 123236642Smarius{ 124236642Smarius vga_softc_t *sc; 125185721Smav struct resource *port; 126236642Smarius struct resource *mem; 127236642Smarius int unit; 128236642Smarius int rid; 129236642Smarius int error; 130163516Simp 131163516Simp unit = device_get_unit(dev); 132163516Simp sc = device_get_softc(dev); 133183444Simp 134183444Simp rid = 0; 135163516Simp port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 136163516Simp 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 137163516Simp rid = 0; 138163516Simp mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 139163516Simp 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 140236642Smarius 141236642Smarius error = vga_attach_unit(unit, sc, device_get_flags(dev)); 142236642Smarius if (error) 143236642Smarius return error; 144236642Smarius 145236642Smarius#ifdef FB_INSTALL_CDEV 146236642Smarius /* attach a virtual frame buffer device */ 147236642Smarius error = fb_attach(makedev(0, VGA_MKMINOR(unit)), sc->adp, &isavga_cdevsw); 148183763Smav if (error) 149236642Smarius return error; 150236642Smarius#endif /* FB_INSTALL_CDEV */ 151236642Smarius 152236642Smarius if (bootverbose) 153236642Smarius (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose); 154236642Smarius 155236642Smarius#if experimental 156236642Smarius device_add_child(dev, "fb", -1); 157236642Smarius bus_generic_attach(dev); 158236642Smarius#endif 159236642Smarius 160236642Smarius return 0; 161236642Smarius} 162236642Smarius 163236642Smarius#ifdef FB_INSTALL_CDEV 164183449Simp 165236642Smariusstatic int 166236642Smariusisavga_open(dev_t dev, int flag, int mode, struct thread *td) 167236642Smarius{ 168236642Smarius return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); 169236642Smarius} 170236642Smarius 171236642Smariusstatic int 172236642Smariusisavga_close(dev_t dev, int flag, int mode, struct thread *td) 173236642Smarius{ 174236642Smarius return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); 175236642Smarius} 176236642Smarius 177236642Smariusstatic int 178236642Smariusisavga_read(dev_t dev, struct uio *uio, int flag) 179236642Smarius{ 180236642Smarius return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 181236642Smarius} 182236642Smarius 183236642Smariusstatic int 184236642Smariusisavga_write(dev_t dev, struct uio *uio, int flag) 185236642Smarius{ 186236642Smarius return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 187236642Smarius} 188236642Smarius 189236642Smariusstatic int 190236642Smariusisavga_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td) 191236642Smarius{ 192163516Simp return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td); 193163516Simp} 194163516Simp 195163516Simpstatic int 196236642Smariusisavga_mmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int prot) 197236642Smarius{ 198163516Simp return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot); 199163516Simp} 200163516Simp 201163516Simp#endif /* FB_INSTALL_CDEV */ 202236642Smarius 203163516Simpstatic device_method_t isavga_methods[] = { 204163516Simp DEVMETHOD(device_identify, isavga_identify), 205163516Simp DEVMETHOD(device_probe, isavga_probe), 206163516Simp DEVMETHOD(device_attach, isavga_attach), 207163516Simp 208163516Simp DEVMETHOD(bus_print_child, bus_generic_print_child), 209163516Simp { 0, 0 } 210183445Simp}; 211163516Simp 212163516Simpstatic driver_t isavga_driver = { 213163516Simp VGA_DRIVER_NAME, 214163516Simp isavga_methods, 215163516Simp sizeof(vga_softc_t), 216163516Simp}; 217163516Simp 218163516SimpDRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0); 219163516Simp