Home | History | Annotate | Line # | Download | only in isa
isa_io.c revision 1.2
      1  1.1  joff /*	$NetBSD: isa_io.c,v 1.2 2005/01/09 21:32:08 joff Exp $	*/
      2  1.1  joff 
      3  1.1  joff /*
      4  1.1  joff  * Copyright 1997
      5  1.1  joff  * Digital Equipment Corporation. All rights reserved.
      6  1.1  joff  *
      7  1.1  joff  * This software is furnished under license and may be used and
      8  1.1  joff  * copied only in accordance with the following terms and conditions.
      9  1.1  joff  * Subject to these conditions, you may download, copy, install,
     10  1.1  joff  * use, modify and distribute this software in source and/or binary
     11  1.1  joff  * form. No title or ownership is transferred hereby.
     12  1.1  joff  *
     13  1.1  joff  * 1) Any source code used, modified or distributed must reproduce
     14  1.1  joff  *    and retain this copyright notice and list of conditions as
     15  1.1  joff  *    they appear in the source file.
     16  1.1  joff  *
     17  1.1  joff  * 2) No right is granted to use any trade name, trademark, or logo of
     18  1.1  joff  *    Digital Equipment Corporation. Neither the "Digital Equipment
     19  1.1  joff  *    Corporation" name nor any trademark or logo of Digital Equipment
     20  1.1  joff  *    Corporation may be used to endorse or promote products derived
     21  1.1  joff  *    from this software without the prior written permission of
     22  1.1  joff  *    Digital Equipment Corporation.
     23  1.1  joff  *
     24  1.1  joff  * 3) This software is provided "AS-IS" and any express or implied
     25  1.1  joff  *    warranties, including but not limited to, any implied warranties
     26  1.1  joff  *    of merchantability, fitness for a particular purpose, or
     27  1.1  joff  *    non-infringement are disclaimed. In no event shall DIGITAL be
     28  1.1  joff  *    liable for any damages whatsoever, and in particular, DIGITAL
     29  1.1  joff  *    shall not be liable for special, indirect, consequential, or
     30  1.1  joff  *    incidental damages or damages for lost profits, loss of
     31  1.1  joff  *    revenue or loss of use, whether such damages arise in contract,
     32  1.1  joff  *    negligence, tort, under statute, in equity, at law or otherwise,
     33  1.1  joff  *    even if advised of the possibility of such damage.
     34  1.1  joff  */
     35  1.1  joff 
     36  1.1  joff /*
     37  1.1  joff  * bus_space I/O functions for isa
     38  1.1  joff  */
     39  1.1  joff 
     40  1.1  joff #include <sys/cdefs.h>
     41  1.1  joff __KERNEL_RCSID(0, "$NetBSD: isa_io.c,v 1.2 2005/01/09 21:32:08 joff Exp $");
     42  1.1  joff 
     43  1.1  joff #include <sys/param.h>
     44  1.1  joff #include <sys/systm.h>
     45  1.2  joff #include <sys/malloc.h>
     46  1.2  joff #include <sys/extent.h>
     47  1.1  joff #include <machine/bus.h>
     48  1.1  joff #include <machine/pio.h>
     49  1.1  joff #include <machine/isa_machdep.h>
     50  1.1  joff 
     51  1.1  joff /* Proto types for all the bus_space structure functions */
     52  1.1  joff 
     53  1.1  joff bs_protos(isa);
     54  1.1  joff bs_protos(bs_notimpl);
     55  1.2  joff void isa_bs_mallocok(void);
     56  1.1  joff 
     57  1.1  joff /*
     58  1.1  joff  * Declare the isa bus space tags
     59  1.1  joff  * The IO and MEM structs are identical, except for the cookies,
     60  1.1  joff  * which contain the address space bases.
     61  1.1  joff  */
     62  1.1  joff 
     63  1.1  joff /*
     64  1.1  joff  * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
     65  1.1  joff  *       THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF 16 BIT ISA/IO!
     66  1.1  joff  */
     67  1.1  joff struct bus_space isa_io_bs_tag = {
     68  1.1  joff 	/* cookie */
     69  1.1  joff 	NULL, /* initialized below */
     70  1.1  joff 
     71  1.1  joff 	/* mapping/unmapping */
     72  1.1  joff 	isa_bs_map,
     73  1.1  joff 	isa_bs_unmap,
     74  1.1  joff 	isa_bs_subregion,
     75  1.1  joff 
     76  1.1  joff 	/* allocation/deallocation */
     77  1.1  joff 	isa_bs_alloc,
     78  1.1  joff 	isa_bs_free,
     79  1.1  joff 
     80  1.1  joff 	/* get kernel virtual address */
     81  1.1  joff 	isa_bs_vaddr,
     82  1.1  joff 
     83  1.1  joff 	/* mmap bus space for userland */
     84  1.1  joff 	bs_notimpl_bs_mmap,		/* XXX possible even? XXX */
     85  1.1  joff 
     86  1.1  joff 	/* barrier */
     87  1.1  joff 	isa_bs_barrier,
     88  1.1  joff 
     89  1.1  joff 	/* read (single) */
     90  1.1  joff 	isa_bs_r_1,
     91  1.1  joff 	isa_bs_r_2,
     92  1.1  joff 	isa_bs_r_4,
     93  1.1  joff 	bs_notimpl_bs_r_8,
     94  1.1  joff 
     95  1.1  joff 	/* read multiple */
     96  1.1  joff 	isa_bs_rm_1,
     97  1.1  joff 	isa_bs_rm_2,
     98  1.1  joff 	isa_bs_rm_4,
     99  1.1  joff 	bs_notimpl_bs_rm_8,
    100  1.1  joff 
    101  1.1  joff 	/* read region */
    102  1.1  joff 	isa_bs_rr_1,
    103  1.1  joff 	isa_bs_rr_2,
    104  1.1  joff 	isa_bs_rr_4,
    105  1.1  joff 	bs_notimpl_bs_rr_8,
    106  1.1  joff 
    107  1.1  joff 	/* write (single) */
    108  1.1  joff 	isa_bs_w_1,
    109  1.1  joff 	isa_bs_w_2,
    110  1.1  joff 	isa_bs_w_4,
    111  1.1  joff 	bs_notimpl_bs_w_8,
    112  1.1  joff 
    113  1.1  joff 	/* write multiple */
    114  1.1  joff 	isa_bs_wm_1,
    115  1.1  joff 	isa_bs_wm_2,
    116  1.1  joff 	isa_bs_wm_4,
    117  1.1  joff 	bs_notimpl_bs_wm_8,
    118  1.1  joff 
    119  1.1  joff 	/* write region */
    120  1.1  joff 	isa_bs_wr_1,
    121  1.1  joff 	isa_bs_wr_2,
    122  1.1  joff 	isa_bs_wr_4,
    123  1.1  joff 	bs_notimpl_bs_wr_8,
    124  1.1  joff 
    125  1.1  joff 	/* set multiple */
    126  1.1  joff 	bs_notimpl_bs_sm_1,
    127  1.1  joff 	bs_notimpl_bs_sm_2,
    128  1.1  joff 	bs_notimpl_bs_sm_4,
    129  1.1  joff 	bs_notimpl_bs_sm_8,
    130  1.1  joff 
    131  1.1  joff 	/* set region */
    132  1.1  joff 	bs_notimpl_bs_sr_1,
    133  1.1  joff 	isa_bs_sr_2,
    134  1.1  joff 	bs_notimpl_bs_sr_4,
    135  1.1  joff 	bs_notimpl_bs_sr_8,
    136  1.1  joff 
    137  1.1  joff 	/* copy */
    138  1.1  joff 	bs_notimpl_bs_c_1,
    139  1.1  joff 	bs_notimpl_bs_c_2,
    140  1.1  joff 	bs_notimpl_bs_c_4,
    141  1.1  joff 	bs_notimpl_bs_c_8,
    142  1.1  joff };
    143  1.1  joff 
    144  1.1  joff /*
    145  1.1  joff  * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
    146  1.1  joff  *       THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY!
    147  1.1  joff  */
    148  1.1  joff struct bus_space isa_mem_bs_tag = {
    149  1.1  joff 	/* cookie */
    150  1.1  joff         NULL, /* initialized below */
    151  1.1  joff 
    152  1.1  joff 	/* mapping/unmapping */
    153  1.1  joff 	isa_bs_map,
    154  1.1  joff 	isa_bs_unmap,
    155  1.1  joff 	isa_bs_subregion,
    156  1.1  joff 
    157  1.1  joff 	/* allocation/deallocation */
    158  1.1  joff 	isa_bs_alloc,
    159  1.1  joff 	isa_bs_free,
    160  1.1  joff 
    161  1.1  joff 	/* get kernel virtual address */
    162  1.1  joff 	isa_bs_vaddr,
    163  1.1  joff 
    164  1.1  joff 	/* mmap bus space for userland */
    165  1.1  joff 	bs_notimpl_bs_mmap,		/* XXX open for now ... XXX */
    166  1.1  joff 
    167  1.1  joff 	/* barrier */
    168  1.1  joff 	isa_bs_barrier,
    169  1.1  joff 
    170  1.1  joff 	/* read (single) */
    171  1.1  joff 	isa_bs_r_1,
    172  1.1  joff 	isa_bs_r_2,
    173  1.1  joff 	isa_bs_r_4,
    174  1.1  joff 	bs_notimpl_bs_r_8,
    175  1.1  joff 
    176  1.1  joff 	/* read multiple */
    177  1.1  joff 	isa_bs_rm_1,
    178  1.1  joff 	isa_bs_rm_2,
    179  1.1  joff 	isa_bs_rm_4,
    180  1.1  joff 	bs_notimpl_bs_rm_8,
    181  1.1  joff 
    182  1.1  joff 	/* read region */
    183  1.1  joff 	isa_bs_rr_1,
    184  1.1  joff 	isa_bs_rr_2,
    185  1.1  joff 	isa_bs_rr_4,
    186  1.1  joff 	bs_notimpl_bs_rr_8,
    187  1.1  joff 
    188  1.1  joff 	/* write (single) */
    189  1.1  joff 	isa_bs_w_1,
    190  1.1  joff 	isa_bs_w_2,
    191  1.1  joff 	isa_bs_w_4,
    192  1.1  joff 	bs_notimpl_bs_w_8,
    193  1.1  joff 
    194  1.1  joff 	/* write multiple */
    195  1.1  joff 	isa_bs_wm_1,
    196  1.1  joff 	isa_bs_wm_2,
    197  1.1  joff 	isa_bs_wm_4,
    198  1.1  joff 	bs_notimpl_bs_wm_8,
    199  1.1  joff 
    200  1.1  joff 	/* write region */
    201  1.1  joff 	isa_bs_wr_1,
    202  1.1  joff 	isa_bs_wr_2,
    203  1.1  joff 	isa_bs_wr_4,
    204  1.1  joff 	bs_notimpl_bs_wr_8,
    205  1.1  joff 
    206  1.1  joff 	/* set multiple */
    207  1.1  joff 	bs_notimpl_bs_sm_1,
    208  1.1  joff 	bs_notimpl_bs_sm_2,
    209  1.1  joff 	bs_notimpl_bs_sm_4,
    210  1.1  joff 	bs_notimpl_bs_sm_8,
    211  1.1  joff 
    212  1.1  joff 	/* set region */
    213  1.1  joff 	bs_notimpl_bs_sr_1,
    214  1.1  joff 	isa_bs_sr_2,
    215  1.1  joff 	bs_notimpl_bs_sr_4,
    216  1.1  joff 	bs_notimpl_bs_sr_8,
    217  1.1  joff 
    218  1.1  joff 	/* copy */
    219  1.1  joff 	bs_notimpl_bs_c_1,
    220  1.1  joff 	bs_notimpl_bs_c_2,
    221  1.1  joff 	bs_notimpl_bs_c_4,
    222  1.1  joff 	bs_notimpl_bs_c_8,
    223  1.1  joff };
    224  1.1  joff 
    225  1.2  joff static long isaio_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
    226  1.2  joff static long isamem_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
    227  1.2  joff static int malloc_safe = 0;
    228  1.2  joff struct extent	*isaio_ex;
    229  1.2  joff struct extent	*isamem_ex;
    230  1.2  joff 
    231  1.2  joff void
    232  1.2  joff isa_bs_mallocok(void)
    233  1.2  joff {
    234  1.2  joff 	malloc_safe = 1;
    235  1.2  joff }
    236  1.2  joff 
    237  1.1  joff /* bus space functions */
    238  1.1  joff 
    239  1.1  joff void
    240  1.1  joff isa_io_init(isa_io_addr, isa_mem_addr)
    241  1.1  joff 	vm_offset_t isa_io_addr;
    242  1.1  joff 	vm_offset_t isa_mem_addr;
    243  1.1  joff {
    244  1.1  joff 	isa_io_bs_tag.bs_cookie = (void *)isa_io_addr;
    245  1.1  joff 	isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr;
    246  1.2  joff 
    247  1.2  joff 	isaio_ex = extent_create("isaio", 0x0, 0xffff, M_DEVBUF,
    248  1.2  joff 		(caddr_t)isaio_ex_storage, sizeof(isaio_ex_storage),
    249  1.2  joff 		EX_NOWAIT|EX_NOCOALESCE);
    250  1.2  joff 	isamem_ex = extent_create("isamem", 0x0, 0xfffff, M_DEVBUF,
    251  1.2  joff 		(caddr_t)isamem_ex_storage, sizeof(isamem_ex_storage),
    252  1.2  joff 		EX_NOWAIT|EX_NOCOALESCE);
    253  1.2  joff 	if (isaio_ex == NULL || isamem_ex == NULL)
    254  1.2  joff 		panic("isa_io_init(): can't alloc extent maps");
    255  1.1  joff }
    256  1.1  joff 
    257  1.1  joff /*
    258  1.1  joff  * break the abstraction: sometimes, other parts of the system
    259  1.1  joff  * (e.g. X servers) need to map ISA space directly.  use these
    260  1.1  joff  * functions sparingly!
    261  1.1  joff  */
    262  1.1  joff vm_offset_t
    263  1.1  joff isa_io_data_vaddr(void)
    264  1.1  joff {
    265  1.1  joff 	return (vm_offset_t)isa_io_bs_tag.bs_cookie;
    266  1.1  joff }
    267  1.1  joff 
    268  1.1  joff vm_offset_t
    269  1.1  joff isa_mem_data_vaddr(void)
    270  1.1  joff {
    271  1.1  joff 	return (vm_offset_t)isa_mem_bs_tag.bs_cookie;
    272  1.1  joff }
    273  1.1  joff 
    274  1.1  joff int
    275  1.1  joff isa_bs_map(t, bpa, size, cacheable, bshp)
    276  1.1  joff 	void *t;
    277  1.1  joff 	bus_addr_t bpa;
    278  1.1  joff 	bus_size_t size;
    279  1.1  joff 	int cacheable;
    280  1.1  joff 	bus_space_handle_t *bshp;
    281  1.1  joff {
    282  1.2  joff 	struct extent *ex;
    283  1.2  joff 	int err;
    284  1.2  joff 
    285  1.2  joff 	if (t == &isa_io_bs_tag)
    286  1.2  joff 		ex = isaio_ex;
    287  1.2  joff 	else
    288  1.2  joff 		ex = isamem_ex;
    289  1.2  joff 
    290  1.2  joff 	err = extent_alloc_region(ex, bpa, size,
    291  1.2  joff 		EX_NOWAIT|(malloc_safe ? EX_MALLOCOK : 0));
    292  1.2  joff 	if (err)
    293  1.2  joff 		return err;
    294  1.2  joff 
    295  1.1  joff 	*bshp = bpa + (bus_addr_t)t;
    296  1.1  joff 	return(0);
    297  1.1  joff }
    298  1.1  joff 
    299  1.1  joff void
    300  1.1  joff isa_bs_unmap(t, bsh, size)
    301  1.1  joff 	void *t;
    302  1.1  joff 	bus_space_handle_t bsh;
    303  1.1  joff 	bus_size_t size;
    304  1.1  joff {
    305  1.2  joff 	isa_bs_free(t, bsh, size);
    306  1.1  joff }
    307  1.1  joff 
    308  1.1  joff int
    309  1.1  joff isa_bs_subregion(t, bsh, offset, size, nbshp)
    310  1.1  joff 	void *t;
    311  1.1  joff 	bus_space_handle_t bsh;
    312  1.1  joff 	bus_size_t offset, size;
    313  1.1  joff 	bus_space_handle_t *nbshp;
    314  1.1  joff {
    315  1.1  joff /*	printf("isa_subregion(tag=%p, bsh=%lx, off=%lx, sz=%lx)\n",
    316  1.1  joff 	    t, bsh, offset, size);*/
    317  1.1  joff 	*nbshp = bsh + offset;
    318  1.1  joff 	return(0);
    319  1.1  joff }
    320  1.1  joff 
    321  1.1  joff int
    322  1.1  joff isa_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
    323  1.1  joff     bpap, bshp)
    324  1.1  joff 	void *t;
    325  1.1  joff 	bus_addr_t rstart, rend;
    326  1.1  joff 	bus_size_t size, alignment, boundary;
    327  1.1  joff 	int cacheable;
    328  1.1  joff 	bus_addr_t *bpap;
    329  1.1  joff 	bus_space_handle_t *bshp;
    330  1.1  joff {
    331  1.2  joff 	struct extent *ex;
    332  1.2  joff 	u_long bpa;
    333  1.2  joff 	int err;
    334  1.2  joff 
    335  1.2  joff 	if (t == &isa_io_bs_tag)
    336  1.2  joff 		ex = isaio_ex;
    337  1.2  joff 	else
    338  1.2  joff 		ex = isamem_ex;
    339  1.2  joff 
    340  1.2  joff 	err = extent_alloc_subregion(ex, rstart, rend, size, alignment,
    341  1.2  joff 		boundary, (EX_FAST|EX_NOWAIT|(malloc_safe ? EX_MALLOCOK : 0)),
    342  1.2  joff 		&bpa);
    343  1.2  joff 
    344  1.2  joff 	if (err)
    345  1.2  joff 		return err;
    346  1.2  joff 
    347  1.2  joff 	*bshp = *bpap = bpa;
    348  1.2  joff 	return 0;
    349  1.1  joff }
    350  1.1  joff 
    351  1.1  joff void
    352  1.1  joff isa_bs_free(t, bsh, size)
    353  1.1  joff 	void *t;
    354  1.1  joff 	bus_space_handle_t bsh;
    355  1.1  joff 	bus_size_t size;
    356  1.1  joff {
    357  1.2  joff 	struct extent *ex;
    358  1.2  joff 
    359  1.2  joff 	if (t == &isa_io_bs_tag)
    360  1.2  joff 		ex = isaio_ex;
    361  1.2  joff 	else
    362  1.2  joff 		ex = isamem_ex;
    363  1.2  joff 
    364  1.2  joff 	extent_free(ex, bsh - (bus_addr_t)t, size,
    365  1.2  joff 		EX_NOWAIT|(malloc_safe ? EX_MALLOCOK : 0));
    366  1.1  joff }
    367  1.1  joff 
    368  1.1  joff void *
    369  1.1  joff isa_bs_vaddr(t, bsh)
    370  1.1  joff 	void *t;
    371  1.1  joff 	bus_space_handle_t bsh;
    372  1.1  joff {
    373  1.1  joff 
    374  1.1  joff 	return ((void *)bsh);
    375  1.1  joff }
    376  1.1  joff 
    377  1.1  joff void
    378  1.1  joff isa_bs_barrier(t, bsh, offset, len, flags)
    379  1.1  joff 	void *t;
    380  1.1  joff 	bus_space_handle_t bsh;
    381  1.1  joff 	bus_size_t offset, len;
    382  1.1  joff 	int flags;
    383  1.1  joff {
    384  1.1  joff 	/* just return */
    385  1.1  joff }
    386