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