vga_isa.c (198964) | vga_isa.c (199002) |
---|---|
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 --- 11 unchanged lines hidden (view full) --- 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 --- 11 unchanged lines hidden (view full) --- 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 198964 2009-11-05 22:58:50Z jkim $"); | 28__FBSDID("$FreeBSD: head/sys/isa/vga_isa.c 199002 2009-11-06 20:32:26Z 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> --- 75 unchanged lines hidden (view full) --- 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 } | 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> --- 75 unchanged lines hidden (view full) --- 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; | 120 return (error); |
121} 122 123static int 124isavga_attach(device_t dev) 125{ 126 vga_softc_t *sc; | 121} 122 123static int 124isavga_attach(device_t dev) 125{ 126 vga_softc_t *sc; |
127 devclass_t dc; 128 device_t *devs; 129 void *vgapci_sc; 130 int count, i; |
|
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) | 131 int unit; 132 int rid; 133 int error; 134 135 unit = device_get_unit(dev); 136 sc = device_get_softc(dev); 137 138 rid = 0; 139 bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 140 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 141 rid = 0; 142 bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 143 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 144 145 error = vga_attach_unit(unit, sc, device_get_flags(dev)); 146 if (error) |
143 return error; | 147 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) | 148 149#ifdef FB_INSTALL_CDEV 150 /* attach a virtual frame buffer device */ 151 error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw); 152 if (error) |
149 return error; | 153 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 | 154#endif /* FB_INSTALL_CDEV */ 155 156 if (0 && bootverbose) 157 vidd_diag(sc->adp, bootverbose); 158 159#if 0 /* experimental */ 160 device_add_child(dev, "fb", -1); 161 bus_generic_attach(dev); 162#endif 163 |
160 return 0; | 164 /* Find the matching PCI video controller. */ 165 if (unit == 0) { 166 dc = devclass_find("vgapci"); 167 if (dc != NULL && 168 devclass_get_devices(dc, &devs, &count) == 0) { 169 for (i = 0; i < count; i++) 170 if (device_get_flags(devs[i]) != 0) { 171 sc->pci_dev = devs[i]; 172 break; 173 } 174 free(devs, M_TEMP); 175 } 176 if (sc->pci_dev != NULL) { 177 vgapci_sc = device_get_softc(sc->pci_dev); 178 *(device_t *)vgapci_sc = dev; 179 device_printf(dev, "associated with %s\n", 180 device_get_nameunit(sc->pci_dev)); 181 } 182 } 183 184 return (0); |
161} 162 163static int 164isavga_suspend(device_t dev) 165{ 166 vga_softc_t *sc; | 185} 186 187static int 188isavga_suspend(device_t dev) 189{ 190 vga_softc_t *sc; |
191 device_t isa_dev; |
|
167 int err, nbytes; 168 | 192 int err, nbytes; 193 |
169 err = bus_generic_suspend(dev); 170 if (err) 171 return (err); | 194 err = 0; 195 isa_dev = dev; 196 sc = device_get_softc(isa_dev); 197 if (sc->pci_dev != NULL) 198 dev = sc->pci_dev; 199 else 200 err = bus_generic_suspend(isa_dev); |
172 | 201 |
173 sc = device_get_softc(dev); 174 | |
175 /* Save the video state across the suspend. */ 176 if (sc->state_buf != NULL) 177 goto save_palette; 178 nbytes = vidd_save_state(sc->adp, NULL, 0); 179 if (nbytes <= 0) 180 goto save_palette; 181 sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT); 182 if (sc->state_buf == NULL) --- 5 unchanged lines hidden (view full) --- 188 nbytes); 189 free(sc->state_buf, M_TEMP); 190 sc->state_buf = NULL; 191 } 192 193save_palette: 194 /* Save the color palette across the suspend. */ 195 if (sc->pal_buf != NULL) | 202 /* Save the video state across the suspend. */ 203 if (sc->state_buf != NULL) 204 goto save_palette; 205 nbytes = vidd_save_state(sc->adp, NULL, 0); 206 if (nbytes <= 0) 207 goto save_palette; 208 sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT); 209 if (sc->state_buf == NULL) --- 5 unchanged lines hidden (view full) --- 215 nbytes); 216 free(sc->state_buf, M_TEMP); 217 sc->state_buf = NULL; 218 } 219 220save_palette: 221 /* Save the color palette across the suspend. */ 222 if (sc->pal_buf != NULL) |
196 return (0); | 223 return (err); |
197 sc->pal_buf = malloc(256 * 3, M_TEMP, M_NOWAIT); 198 if (sc->pal_buf != NULL) { 199 if (bootverbose) 200 device_printf(dev, "saving color palette\n"); 201 if (vidd_save_palette(sc->adp, sc->pal_buf) != 0) { 202 device_printf(dev, "failed to save palette\n"); 203 free(sc->pal_buf, M_TEMP); 204 sc->pal_buf = NULL; 205 } 206 } 207 | 224 sc->pal_buf = malloc(256 * 3, M_TEMP, M_NOWAIT); 225 if (sc->pal_buf != NULL) { 226 if (bootverbose) 227 device_printf(dev, "saving color palette\n"); 228 if (vidd_save_palette(sc->adp, sc->pal_buf) != 0) { 229 device_printf(dev, "failed to save palette\n"); 230 free(sc->pal_buf, M_TEMP); 231 sc->pal_buf = NULL; 232 } 233 } 234 |
208 return (0); | 235 return (err); |
209} 210 211static int 212isavga_resume(device_t dev) 213{ 214 vga_softc_t *sc; | 236} 237 238static int 239isavga_resume(device_t dev) 240{ 241 vga_softc_t *sc; |
242 device_t isa_dev; |
|
215 | 243 |
216 sc = device_get_softc(dev); | 244 isa_dev = dev; 245 sc = device_get_softc(isa_dev); 246 if (sc->pci_dev != NULL) 247 dev = sc->pci_dev; |
217 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 } 230 | 248 249 if (sc->state_buf != NULL) { 250 if (vidd_load_state(sc->adp, sc->state_buf) != 0) 251 device_printf(dev, "failed to reload state\n"); 252 free(sc->state_buf, M_TEMP); 253 sc->state_buf = NULL; 254 } 255 if (sc->pal_buf != NULL) { 256 if (vidd_load_palette(sc->adp, sc->pal_buf) != 0) 257 device_printf(dev, "failed to reload palette\n"); 258 free(sc->pal_buf, M_TEMP); 259 sc->pal_buf = NULL; 260 } 261 |
231 return (bus_generic_resume(dev)); | 262 if (isa_dev != dev) 263 return (0); 264 265 return (bus_generic_resume(isa_dev)); |
232} 233 234#ifdef FB_INSTALL_CDEV 235 236static int 237isavga_open(struct cdev *dev, int flag, int mode, struct thread *td) 238{ | 266} 267 268#ifdef FB_INSTALL_CDEV 269 270static int 271isavga_open(struct cdev *dev, int flag, int mode, struct thread *td) 272{ |
239 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); | 273 return (vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td)); |
240} 241 242static int 243isavga_close(struct cdev *dev, int flag, int mode, struct thread *td) 244{ | 274} 275 276static int 277isavga_close(struct cdev *dev, int flag, int mode, struct thread *td) 278{ |
245 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); | 279 return (vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td)); |
246} 247 248static int 249isavga_read(struct cdev *dev, struct uio *uio, int flag) 250{ | 280} 281 282static int 283isavga_read(struct cdev *dev, struct uio *uio, int flag) 284{ |
251 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); | 285 return (vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag)); |
252} 253 254static int 255isavga_write(struct cdev *dev, struct uio *uio, int flag) 256{ | 286} 287 288static int 289isavga_write(struct cdev *dev, struct uio *uio, int flag) 290{ |
257 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); | 291 return (vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag)); |
258} 259 260static int 261isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td) 262{ | 292} 293 294static int 295isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td) 296{ |
263 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td); | 297 return (vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td)); |
264} 265 266static int 267isavga_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot) 268{ | 298} 299 300static int 301isavga_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot) 302{ |
269 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot); | 303 return (vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot)); |
270} 271 272#endif /* FB_INSTALL_CDEV */ 273 274static device_method_t isavga_methods[] = { 275 DEVMETHOD(device_identify, isavga_identify), 276 DEVMETHOD(device_probe, isavga_probe), 277 DEVMETHOD(device_attach, isavga_attach), --- 14 unchanged lines hidden --- | 304} 305 306#endif /* FB_INSTALL_CDEV */ 307 308static device_method_t isavga_methods[] = { 309 DEVMETHOD(device_identify, isavga_identify), 310 DEVMETHOD(device_probe, isavga_probe), 311 DEVMETHOD(device_attach, isavga_attach), --- 14 unchanged lines hidden --- |