Home | History | Annotate | Line # | Download | only in isa
isa_io.c revision 1.11
      1  1.11      matt /*	$NetBSD: isa_io.c,v 1.11 2014/09/13 18:08:39 matt 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.11      matt __KERNEL_RCSID(0, "$NetBSD: isa_io.c,v 1.11 2014/09/13 18:08:39 matt 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.8    dyoung #include <sys/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.11      matt isa_io_init(vaddr_t isa_io_addr, vaddr_t isa_mem_addr)
    241   1.1      joff {
    242   1.1      joff 	isa_io_bs_tag.bs_cookie = (void *)isa_io_addr;
    243   1.1      joff 	isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr;
    244   1.2      joff 
    245   1.9      para 	isaio_ex = extent_create("isaio", 0x0, 0xffff,
    246   1.5  christos 		(void *)isaio_ex_storage, sizeof(isaio_ex_storage),
    247   1.2      joff 		EX_NOWAIT|EX_NOCOALESCE);
    248   1.9      para 	isamem_ex = extent_create("isamem", 0x0, 0xfffff,
    249   1.5  christos 		(void *)isamem_ex_storage, sizeof(isamem_ex_storage),
    250   1.2      joff 		EX_NOWAIT|EX_NOCOALESCE);
    251   1.2      joff 	if (isaio_ex == NULL || isamem_ex == NULL)
    252   1.2      joff 		panic("isa_io_init(): can't alloc extent maps");
    253   1.1      joff }
    254   1.1      joff 
    255   1.1      joff /*
    256   1.1      joff  * break the abstraction: sometimes, other parts of the system
    257   1.1      joff  * (e.g. X servers) need to map ISA space directly.  use these
    258   1.1      joff  * functions sparingly!
    259   1.1      joff  */
    260  1.11      matt vaddr_t
    261   1.1      joff isa_io_data_vaddr(void)
    262   1.1      joff {
    263  1.11      matt 	return (vaddr_t)isa_io_bs_tag.bs_cookie;
    264   1.1      joff }
    265   1.1      joff 
    266  1.11      matt vaddr_t
    267   1.1      joff isa_mem_data_vaddr(void)
    268   1.1      joff {
    269  1.11      matt 	return (vaddr_t)isa_mem_bs_tag.bs_cookie;
    270   1.1      joff }
    271   1.1      joff 
    272   1.1      joff int
    273   1.6       dsl isa_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
    274   1.1      joff {
    275   1.2      joff 	struct extent *ex;
    276   1.2      joff 	int err;
    277   1.2      joff 
    278   1.3      joff 	if (t == isa_io_bs_tag.bs_cookie)
    279   1.2      joff 		ex = isaio_ex;
    280   1.2      joff 	else
    281   1.2      joff 		ex = isamem_ex;
    282   1.2      joff 
    283   1.2      joff 	err = extent_alloc_region(ex, bpa, size,
    284   1.2      joff 		EX_NOWAIT|(malloc_safe ? EX_MALLOCOK : 0));
    285   1.2      joff 	if (err)
    286   1.2      joff 		return err;
    287   1.2      joff 
    288   1.1      joff 	*bshp = bpa + (bus_addr_t)t;
    289   1.1      joff 	return(0);
    290   1.1      joff }
    291   1.1      joff 
    292   1.1      joff void
    293   1.6       dsl isa_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    294   1.1      joff {
    295   1.2      joff 	isa_bs_free(t, bsh, size);
    296   1.1      joff }
    297   1.1      joff 
    298   1.1      joff int
    299   1.7       dsl isa_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    300   1.1      joff {
    301   1.1      joff 	*nbshp = bsh + offset;
    302   1.1      joff 	return(0);
    303   1.1      joff }
    304   1.1      joff 
    305   1.1      joff int
    306  1.10      matt isa_bs_alloc(
    307  1.10      matt 	void *t,
    308  1.10      matt 	bus_addr_t rstart,
    309  1.10      matt 	bus_addr_t rend,
    310  1.10      matt 	bus_size_t size,
    311  1.10      matt 	bus_size_t alignment,
    312  1.10      matt 	bus_size_t boundary,
    313  1.10      matt 	int cacheable,
    314  1.10      matt 	bus_addr_t *bpap,
    315  1.10      matt 	bus_space_handle_t *bshp)
    316   1.1      joff {
    317   1.2      joff 	struct extent *ex;
    318   1.2      joff 	u_long bpa;
    319   1.2      joff 	int err;
    320   1.2      joff 
    321   1.3      joff 	if (t == isa_io_bs_tag.bs_cookie)
    322   1.2      joff 		ex = isaio_ex;
    323   1.2      joff 	else
    324   1.2      joff 		ex = isamem_ex;
    325   1.2      joff 
    326   1.2      joff 	err = extent_alloc_subregion(ex, rstart, rend, size, alignment,
    327   1.2      joff 		boundary, (EX_FAST|EX_NOWAIT|(malloc_safe ? EX_MALLOCOK : 0)),
    328   1.2      joff 		&bpa);
    329   1.2      joff 
    330   1.2      joff 	if (err)
    331   1.2      joff 		return err;
    332   1.2      joff 
    333   1.3      joff 	*bshp = *bpap = bpa + (bus_addr_t)t;
    334   1.2      joff 	return 0;
    335   1.1      joff }
    336   1.1      joff 
    337   1.1      joff void
    338   1.6       dsl isa_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    339   1.1      joff {
    340   1.2      joff 	struct extent *ex;
    341   1.2      joff 
    342   1.3      joff 	if (t == isa_io_bs_tag.bs_cookie)
    343   1.2      joff 		ex = isaio_ex;
    344   1.2      joff 	else
    345   1.2      joff 		ex = isamem_ex;
    346   1.2      joff 
    347   1.2      joff 	extent_free(ex, bsh - (bus_addr_t)t, size,
    348   1.2      joff 		EX_NOWAIT|(malloc_safe ? EX_MALLOCOK : 0));
    349   1.1      joff }
    350   1.1      joff 
    351   1.1      joff void *
    352   1.6       dsl isa_bs_vaddr(void *t, bus_space_handle_t bsh)
    353   1.1      joff {
    354   1.1      joff 
    355   1.1      joff 	return ((void *)bsh);
    356   1.1      joff }
    357   1.1      joff 
    358   1.1      joff void
    359   1.7       dsl isa_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
    360   1.1      joff {
    361   1.1      joff 	/* just return */
    362   1.1      joff }
    363