Home | History | Annotate | Line # | Download | only in isa
      1 /*	$NetBSD: isa_io.c,v 1.10 2021/08/13 11:40:43 skrll Exp $	*/
      2 
      3 /*
      4  * Copyright 1997
      5  * Digital Equipment Corporation. All rights reserved.
      6  *
      7  * This software is furnished under license and may be used and
      8  * copied only in accordance with the following terms and conditions.
      9  * Subject to these conditions, you may download, copy, install,
     10  * use, modify and distribute this software in source and/or binary
     11  * form. No title or ownership is transferred hereby.
     12  *
     13  * 1) Any source code used, modified or distributed must reproduce
     14  *    and retain this copyright notice and list of conditions as
     15  *    they appear in the source file.
     16  *
     17  * 2) No right is granted to use any trade name, trademark, or logo of
     18  *    Digital Equipment Corporation. Neither the "Digital Equipment
     19  *    Corporation" name nor any trademark or logo of Digital Equipment
     20  *    Corporation may be used to endorse or promote products derived
     21  *    from this software without the prior written permission of
     22  *    Digital Equipment Corporation.
     23  *
     24  * 3) This software is provided "AS-IS" and any express or implied
     25  *    warranties, including but not limited to, any implied warranties
     26  *    of merchantability, fitness for a particular purpose, or
     27  *    non-infringement are disclaimed. In no event shall DIGITAL be
     28  *    liable for any damages whatsoever, and in particular, DIGITAL
     29  *    shall not be liable for special, indirect, consequential, or
     30  *    incidental damages or damages for lost profits, loss of
     31  *    revenue or loss of use, whether such damages arise in contract,
     32  *    negligence, tort, under statute, in equity, at law or otherwise,
     33  *    even if advised of the possibility of such damage.
     34  */
     35 
     36 /*
     37  * bus_space I/O functions for isa
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: isa_io.c,v 1.10 2021/08/13 11:40:43 skrll Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/bus.h>
     46 #include <machine/pio.h>
     47 #include <machine/isa_machdep.h>
     48 
     49 /* Proto types for all the bus_space structure functions */
     50 
     51 bs_protos(isa);
     52 bs_protos(bs_notimpl);
     53 
     54 /*
     55  * Declare the isa bus space tags
     56  * The IO and MEM structs are identical, except for the cookies,
     57  * which contain the address space bases.
     58  */
     59 
     60 /*
     61  * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
     62  *       THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/IO!
     63  */
     64 struct bus_space isa_io_bs_tag = {
     65 	/* cookie */
     66 	.bs_cookie = NULL, /* initialized below */
     67 
     68 	/* mapping/unmapping */
     69 	.bs_map = isa_bs_map,
     70 	.bs_unmap = isa_bs_unmap,
     71 	.bs_subregion = isa_bs_subregion,
     72 
     73 	/* allocation/deallocation */
     74 	.bs_alloc = isa_bs_alloc,
     75 	.bs_free = isa_bs_free,
     76 
     77 	/* get kernel virtual address */
     78 	.bs_vaddr = isa_bs_vaddr,
     79 
     80 	/* mmap bus space for userland */
     81 	.bs_mmap = bs_notimpl_bs_mmap,		/* XXX possible even? XXX */
     82 
     83 	/* barrier */
     84 	.bs_barrier = isa_bs_barrier,
     85 
     86 	/* read (single) */
     87 	.bs_r_1 = isa_bs_r_1,
     88 	.bs_r_2 = isa_bs_r_2,
     89 	.bs_r_4 = isa_bs_r_4,
     90 	.bs_r_8 = bs_notimpl_bs_r_8,
     91 
     92 	/* read multiple */
     93 	.bs_rm_1 = isa_bs_rm_1,
     94 	.bs_rm_2 = isa_bs_rm_2,
     95 	.bs_rm_4 = isa_bs_rm_4,
     96 	.bs_rm_8 = bs_notimpl_bs_rm_8,
     97 
     98 	/* read region */
     99 	.bs_rr_1 = isa_bs_rr_1,
    100 	.bs_rr_2 = isa_bs_rr_2,
    101 	.bs_rr_4 = isa_bs_rr_4,
    102 	.bs_rr_8 = bs_notimpl_bs_rr_8,
    103 
    104 	/* write (single) */
    105 	.bs_w_1 = isa_bs_w_1,
    106 	.bs_w_2 = isa_bs_w_2,
    107 	.bs_w_4 = isa_bs_w_4,
    108 	.bs_w_8 = bs_notimpl_bs_w_8,
    109 
    110 	/* write multiple */
    111 	.bs_wm_1 = isa_bs_wm_1,
    112 	.bs_wm_2 = isa_bs_wm_2,
    113 	.bs_wm_4 = isa_bs_wm_4,
    114 	.bs_wm_8 = bs_notimpl_bs_wm_8,
    115 
    116 	/* write region */
    117 	.bs_wr_1 = isa_bs_wr_1,
    118 	.bs_wr_2 = isa_bs_wr_2,
    119 	.bs_wr_4 = isa_bs_wr_4,
    120 	.bs_wr_8 = bs_notimpl_bs_wr_8,
    121 
    122 	/* set multiple */
    123 	.bs_sm_1 = bs_notimpl_bs_sm_1,
    124 	.bs_sm_2 = bs_notimpl_bs_sm_2,
    125 	.bs_sm_4 = bs_notimpl_bs_sm_4,
    126 	.bs_sm_8 = bs_notimpl_bs_sm_8,
    127 
    128 	/* set region */
    129 	.bs_sr_1 = bs_notimpl_bs_sr_1,
    130 	.bs_sr_2 = isa_bs_sr_2,
    131 	.bs_sr_4 = bs_notimpl_bs_sr_4,
    132 	.bs_sr_8 = bs_notimpl_bs_sr_8,
    133 
    134 	/* copy */
    135 	.bs_c_1 = bs_notimpl_bs_c_1,
    136 	.bs_c_2 = bs_notimpl_bs_c_2,
    137 	.bs_c_4 = bs_notimpl_bs_c_4,
    138 	.bs_c_8 = bs_notimpl_bs_c_8,
    139 };
    140 
    141 /*
    142  * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
    143  *       THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY!
    144  */
    145 struct bus_space isa_mem_bs_tag = {
    146 	/* cookie */
    147 	.bs_cookie = NULL, /* initialized below */
    148 
    149 	/* mapping/unmapping */
    150 	.bs_map = isa_bs_map,
    151 	.bs_unmap = isa_bs_unmap,
    152 	.bs_subregion = isa_bs_subregion,
    153 
    154 	/* allocation/deallocation */
    155 	.bs_alloc = isa_bs_alloc,
    156 	.bs_free = isa_bs_free,
    157 
    158 	/* get kernel virtual address */
    159 	.bs_vaddr = isa_bs_vaddr,
    160 
    161 	/* mmap bus space for userland */
    162 	.bs_mmap = bs_notimpl_bs_mmap,		/* XXX open for now ... XXX */
    163 
    164 	/* barrier */
    165 	.bs_barrier = isa_bs_barrier,
    166 
    167 	/* read (single) */
    168 	.bs_r_1 = isa_bs_r_1,
    169 	.bs_r_2 = isa_bs_r_2,
    170 	.bs_r_4 = isa_bs_r_4,
    171 	.bs_r_8 = bs_notimpl_bs_r_8,
    172 
    173 	/* read multiple */
    174 	.bs_rm_1 = isa_bs_rm_1,
    175 	.bs_rm_2 = isa_bs_rm_2,
    176 	.bs_rm_4 = isa_bs_rm_4,
    177 	.bs_rm_8 = bs_notimpl_bs_rm_8,
    178 
    179 	/* read region */
    180 	.bs_rr_1 = isa_bs_rr_1,
    181 	.bs_rr_2 = isa_bs_rr_2,
    182 	.bs_rr_4 = isa_bs_rr_4,
    183 	.bs_rr_8 = bs_notimpl_bs_rr_8,
    184 
    185 	/* write (single) */
    186 	.bs_w_1 = isa_bs_w_1,
    187 	.bs_w_2 = isa_bs_w_2,
    188 	.bs_w_4 = isa_bs_w_4,
    189 	.bs_w_8 = bs_notimpl_bs_w_8,
    190 
    191 	/* write multiple */
    192 	.bs_wm_1 = isa_bs_wm_1,
    193 	.bs_wm_2 = isa_bs_wm_2,
    194 	.bs_wm_4 = isa_bs_wm_4,
    195 	.bs_wm_8 = bs_notimpl_bs_wm_8,
    196 
    197 	/* write region */
    198 	.bs_wr_1 = isa_bs_wr_1,
    199 	.bs_wr_2 = isa_bs_wr_2,
    200 	.bs_wr_4 = isa_bs_wr_4,
    201 	.bs_wr_8 = bs_notimpl_bs_wr_8,
    202 
    203 	/* set multiple */
    204 	.bs_sm_1 = bs_notimpl_bs_sm_1,
    205 	.bs_sm_2 = bs_notimpl_bs_sm_2,
    206 	.bs_sm_4 = bs_notimpl_bs_sm_4,
    207 	.bs_sm_8 = bs_notimpl_bs_sm_8,
    208 
    209 	/* set region */
    210 	.bs_sr_1 = bs_notimpl_bs_sr_1,
    211 	.bs_sr_2 = isa_bs_sr_2,
    212 	.bs_sr_4 = bs_notimpl_bs_sr_4,
    213 	.bs_sr_8 = bs_notimpl_bs_sr_8,
    214 
    215 	/* copy */
    216 	.bs_c_1 = bs_notimpl_bs_c_1,
    217 	.bs_c_2 = bs_notimpl_bs_c_2,
    218 	.bs_c_4 = bs_notimpl_bs_c_4,
    219 	.bs_c_8 = bs_notimpl_bs_c_8,
    220 };
    221 
    222 /* bus space functions */
    223 
    224 void
    225 isa_io_init(vaddr_t isa_io_addr, vaddr_t isa_mem_addr)
    226 {
    227 	isa_io_bs_tag.bs_cookie = (void *)isa_io_addr;
    228 	isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr;
    229 }
    230 
    231 /*
    232  * break the abstraction: sometimes, other parts of the system
    233  * (e.g. X servers) need to map ISA space directly.  use these
    234  * functions sparingly!
    235  */
    236 vaddr_t
    237 isa_io_data_vaddr(void)
    238 {
    239 	return (vaddr_t)isa_io_bs_tag.bs_cookie;
    240 }
    241 
    242 vaddr_t
    243 isa_mem_data_vaddr(void)
    244 {
    245 	return (vaddr_t)isa_mem_bs_tag.bs_cookie;
    246 }
    247 
    248 int
    249 isa_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
    250 {
    251 	*bshp = bpa + (bus_addr_t)t;
    252 	return(0);
    253 }
    254 
    255 void
    256 isa_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    257 {
    258 	/* Nothing to do. */
    259 }
    260 
    261 int
    262 isa_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    263 {
    264 /*	printf("isa_subregion(tag=%p, bsh=%lx, off=%lx, sz=%lx)\n",
    265 	    t, bsh, offset, size);*/
    266 	*nbshp = bsh + offset;
    267 	return(0);
    268 }
    269 
    270 int
    271 isa_bs_alloc(
    272 	void *t,
    273 	bus_addr_t rstart,
    274 	bus_addr_t rend,
    275 	bus_size_t size,
    276 	bus_size_t alignment,
    277 	bus_size_t boundary,
    278 	int cacheable,
    279 	bus_addr_t *bpap,
    280 	bus_space_handle_t *bshp)
    281 {
    282 	panic("isa_alloc(): Help!");
    283 }
    284 
    285 void
    286 isa_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    287 {
    288 	panic("isa_free(): Help!");
    289 }
    290 
    291 void *
    292 isa_bs_vaddr(void *t, bus_space_handle_t bsh)
    293 {
    294 
    295 	return ((void *)bsh);
    296 }
    297 
    298 void
    299 isa_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
    300 {
    301 	/* just return */
    302 }
    303