Home | History | Annotate | Line # | Download | only in jazz
      1 /* $NetBSD: vga_jazzio.c,v 1.18 2023/12/20 06:36:02 thorpej Exp $ */
      2 /* NetBSD: vga_isa.c,v 1.3 1998/06/12 18:45:48 drochner Exp  */
      3 
      4 /*
      5  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      6  * All rights reserved.
      7  *
      8  * Author: Chris G. Demetriou
      9  *
     10  * Permission to use, copy, modify and distribute this software and
     11  * its documentation is hereby granted, provided that both the copyright
     12  * notice and this permission notice appear in all copies of the
     13  * software, derivative works or modified versions, and any portions
     14  * thereof, and that both notices appear in supporting documentation.
     15  *
     16  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     17  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     18  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     19  *
     20  * Carnegie Mellon requests users of this software to return to
     21  *
     22  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     23  *  School of Computer Science
     24  *  Carnegie Mellon University
     25  *  Pittsburgh PA 15213-3890
     26  *
     27  * any improvements or extensions that they make and grant Carnegie the
     28  * rights to redistribute these changes.
     29  */
     30 
     31 #include <sys/cdefs.h>
     32 __KERNEL_RCSID(0, "$NetBSD: vga_jazzio.c,v 1.18 2023/12/20 06:36:02 thorpej Exp $");
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/kernel.h>
     37 #include <sys/device.h>
     38 #include <uvm/uvm_extern.h>
     39 
     40 #include <machine/autoconf.h>
     41 #include <sys/bus.h>
     42 #include <machine/wired_map.h>
     43 
     44 #include <mips/pte.h>
     45 
     46 #include <dev/ic/mc6845reg.h>
     47 #include <dev/ic/pcdisplayvar.h>
     48 #include <dev/ic/vgareg.h>
     49 #include <dev/ic/vgavar.h>
     50 
     51 #include <arc/jazz/jazziovar.h>
     52 #include <arc/jazz/pica.h>
     53 #include <arc/jazz/vga_jazziovar.h>
     54 
     55 #include <dev/wscons/wsconsio.h>
     56 #include <dev/wscons/wsdisplayvar.h>
     57 
     58 #define WSDISPLAY_TYPE_JAZZVGA	WSDISPLAY_TYPE_PCIVGA	/* XXX not really */
     59 
     60 int	vga_jazzio_init_tag(const char *, bus_space_tag_t *, bus_space_tag_t *);
     61 paddr_t	vga_jazzio_mmap(void *, off_t, int);
     62 int	vga_jazzio_match(device_t, cfdata_t, void *);
     63 void	vga_jazzio_attach(device_t, device_t, void *);
     64 
     65 CFATTACH_DECL_NEW(vga_jazzio, sizeof(struct vga_softc),
     66     vga_jazzio_match, vga_jazzio_attach, NULL, NULL);
     67 
     68 const struct vga_funcs vga_jazzio_funcs = {
     69 	NULL,
     70 	vga_jazzio_mmap,
     71 };
     72 
     73 int
     74 vga_jazzio_init_tag(const char *name, bus_space_tag_t *iotp,
     75     bus_space_tag_t *memtp)
     76 {
     77 	static int initialized = 0;
     78 	static struct arc_bus_space vga_io, vga_mem;
     79 
     80 	if (strcmp(name, "ALI_S3") != 0)
     81 		return ENXIO;
     82 
     83 	if (!initialized) {
     84 		initialized = 1;
     85 
     86 		arc_bus_space_init(&vga_io, "vga_jazzio_io",
     87 		    PICA_P_LOCAL_VIDEO_CTRL, PICA_V_LOCAL_VIDEO_CTRL,
     88 		    0, PICA_S_LOCAL_VIDEO_CTRL);
     89 		arc_bus_space_init(&vga_mem, "vga_jazzio_mem",
     90 		    PICA_P_LOCAL_VIDEO, PICA_V_LOCAL_VIDEO,
     91 		    0, PICA_S_LOCAL_VIDEO);
     92 
     93 		arc_wired_enter_page(PICA_V_LOCAL_VIDEO_CTRL,
     94 		    PICA_P_LOCAL_VIDEO_CTRL,
     95 		    PICA_S_LOCAL_VIDEO_CTRL / 2);
     96 		arc_wired_enter_page(
     97 		    PICA_V_LOCAL_VIDEO_CTRL + PICA_S_LOCAL_VIDEO_CTRL/2,
     98 		    PICA_P_LOCAL_VIDEO_CTRL + PICA_S_LOCAL_VIDEO_CTRL/2,
     99 		    PICA_S_LOCAL_VIDEO_CTRL / 2);
    100 
    101 		arc_wired_enter_page(PICA_V_LOCAL_VIDEO,
    102 		    PICA_P_LOCAL_VIDEO,
    103 		    PICA_S_LOCAL_VIDEO / 2);
    104 		arc_wired_enter_page(
    105 		    PICA_V_LOCAL_VIDEO + PICA_S_LOCAL_VIDEO / 2,
    106 		    PICA_P_LOCAL_VIDEO + PICA_S_LOCAL_VIDEO / 2,
    107 		    PICA_S_LOCAL_VIDEO / 2);
    108 #if 0
    109 		arc_wired_enter_page(PICA_V_EXTND_VIDEO_CTRL,
    110 		    PICA_P_EXTND_VIDEO_CTRL,
    111 		    PICA_S_EXTND_VIDEO_CTRL / 2);
    112 		arc_wired_enter_page(
    113 		    PICA_V_EXTND_VIDEO_CTRL + PICA_S_EXTND_VIDEO_CTRL / 2,
    114 		    PICA_P_EXTND_VIDEO_CTRL + PICA_S_EXTND_VIDEO_CTRL / 2,
    115 		    PICA_S_EXTND_VIDEO_CTRL / 2);
    116 #endif
    117 	}
    118 	*iotp = &vga_io;
    119 	*memtp = &vga_mem;
    120 	return 0;
    121 }
    122 
    123 paddr_t
    124 vga_jazzio_mmap(void *v, off_t offset, int prot)
    125 {
    126 
    127 	if (offset >= 0xa0000 && offset < 0xc0000)
    128 		return mips_btop(PICA_P_LOCAL_VIDEO + offset);
    129 	if (offset >= 0x0000 && offset < 0x10000)
    130 		return mips_btop(PICA_P_LOCAL_VIDEO_CTRL + offset);
    131 	if (offset >= 0x40000000 && offset < 0x40800000)
    132 		return mips_btop(PICA_P_LOCAL_VIDEO + offset - 0x40000000);
    133 	return -1;
    134 }
    135 
    136 int
    137 vga_jazzio_match(device_t parent, cfdata_t match, void *aux)
    138 {
    139 	struct jazzio_attach_args *ja = aux;
    140 	bus_space_tag_t iot, memt;
    141 
    142 	if (vga_jazzio_init_tag(ja->ja_name, &iot, &memt))
    143 		return 0;
    144 
    145 	if (!vga_is_console(iot, WSDISPLAY_TYPE_JAZZVGA) &&
    146 	    !vga_common_probe(iot, memt))
    147 		return 0;
    148 
    149 	return 1;
    150 }
    151 
    152 void
    153 vga_jazzio_attach(device_t parent, device_t self, void *aux)
    154 {
    155 	struct vga_softc *sc = device_private(self);
    156 	struct jazzio_attach_args *ja = aux;
    157 	bus_space_tag_t iot, memt;
    158 
    159 	aprint_normal("\n");
    160 
    161 	sc->sc_dev = self;
    162 	vga_jazzio_init_tag(ja->ja_name, &iot, &memt);
    163 	vga_common_attach(sc, iot, memt, WSDISPLAY_TYPE_JAZZVGA, 0,
    164 	    &vga_jazzio_funcs);
    165 }
    166 
    167 int
    168 vga_jazzio_cnattach(char *name)
    169 {
    170 	bus_space_tag_t iot, memt;
    171 
    172 	if (vga_jazzio_init_tag(name, &iot, &memt))
    173 		return ENXIO;
    174 	return vga_cnattach(iot, memt, WSDISPLAY_TYPE_JAZZVGA, 1);
    175 }
    176