Home | History | Annotate | Line # | Download | only in isa
isa_io.c revision 1.12.6.1
      1  1.12.6.1  jdolecek /*	$NetBSD: isa_io.c,v 1.12.6.1 2017/12/03 11:36:42 jdolecek 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.12.6.1  jdolecek __KERNEL_RCSID(0, "$NetBSD: isa_io.c,v 1.12.6.1 2017/12/03 11:36:42 jdolecek Exp $");
     42       1.1   thorpej 
     43       1.1   thorpej #include <sys/param.h>
     44       1.1   thorpej #include <sys/systm.h>
     45      1.11    dyoung #include <sys/bus.h>
     46  1.12.6.1  jdolecek #include <uvm/uvm.h>
     47       1.1   thorpej #include <machine/pio.h>
     48       1.1   thorpej #include <machine/isa_machdep.h>
     49       1.7  macallan #include <machine/ofw.h>
     50  1.12.6.1  jdolecek #include <machine/pmap.h>
     51       1.7  macallan #include "igsfb_ofbus.h"
     52  1.12.6.1  jdolecek #include "chipsfb_ofbus.h"
     53       1.7  macallan 
     54       1.7  macallan #if NIGSFB_OFBUS > 0
     55       1.7  macallan extern vaddr_t igsfb_mem_vaddr, igsfb_mmio_vaddr;
     56       1.7  macallan extern paddr_t igsfb_mem_paddr;
     57       1.7  macallan #endif
     58       1.1   thorpej 
     59  1.12.6.1  jdolecek #if NCHIPSFB_OFBUS > 0
     60  1.12.6.1  jdolecek extern vaddr_t chipsfb_mem_vaddr, chipsfb_mmio_vaddr;
     61  1.12.6.1  jdolecek extern paddr_t chipsfb_mem_paddr;
     62  1.12.6.1  jdolecek #endif
     63  1.12.6.1  jdolecek 
     64       1.1   thorpej /* Proto types for all the bus_space structure functions */
     65       1.1   thorpej 
     66       1.1   thorpej bs_protos(isa);
     67       1.1   thorpej bs_protos(bs_notimpl);
     68       1.1   thorpej 
     69       1.1   thorpej /*
     70       1.1   thorpej  * Declare the isa bus space tags
     71       1.1   thorpej  * The IO and MEM structs are identical, except for the cookies,
     72       1.1   thorpej  * which contain the address space bases.
     73       1.1   thorpej  */
     74       1.1   thorpej 
     75       1.1   thorpej /*
     76       1.1   thorpej  * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
     77       1.1   thorpej  *       THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/IO!
     78       1.1   thorpej  */
     79       1.1   thorpej struct bus_space isa_io_bs_tag = {
     80       1.1   thorpej 	/* cookie */
     81       1.7  macallan 	NULL,	/* initialized below */
     82       1.1   thorpej 
     83       1.1   thorpej 	/* mapping/unmapping */
     84       1.1   thorpej 	isa_bs_map,
     85       1.1   thorpej 	isa_bs_unmap,
     86       1.1   thorpej 	isa_bs_subregion,
     87       1.1   thorpej 
     88       1.1   thorpej 	/* allocation/deallocation */
     89       1.1   thorpej 	isa_bs_alloc,
     90       1.1   thorpej 	isa_bs_free,
     91       1.1   thorpej 
     92       1.1   thorpej 	/* get kernel virtual address */
     93       1.1   thorpej 	isa_bs_vaddr,
     94       1.1   thorpej 
     95       1.1   thorpej 	/* mmap bus space for userland */
     96       1.7  macallan 	isa_bs_mmap,
     97       1.1   thorpej 
     98       1.1   thorpej 	/* barrier */
     99       1.1   thorpej 	isa_bs_barrier,
    100       1.1   thorpej 
    101       1.1   thorpej 	/* read (single) */
    102       1.1   thorpej 	isa_bs_r_1,
    103       1.1   thorpej 	isa_bs_r_2,
    104       1.1   thorpej 	isa_bs_r_4,
    105       1.1   thorpej 	bs_notimpl_bs_r_8,
    106       1.1   thorpej 
    107       1.1   thorpej 	/* read multiple */
    108       1.1   thorpej 	isa_bs_rm_1,
    109       1.1   thorpej 	isa_bs_rm_2,
    110       1.1   thorpej 	isa_bs_rm_4,
    111       1.1   thorpej 	bs_notimpl_bs_rm_8,
    112       1.1   thorpej 
    113       1.1   thorpej 	/* read region */
    114       1.1   thorpej 	isa_bs_rr_1,
    115       1.1   thorpej 	isa_bs_rr_2,
    116       1.1   thorpej 	isa_bs_rr_4,
    117       1.1   thorpej 	bs_notimpl_bs_rr_8,
    118       1.1   thorpej 
    119       1.1   thorpej 	/* write (single) */
    120       1.1   thorpej 	isa_bs_w_1,
    121       1.1   thorpej 	isa_bs_w_2,
    122       1.1   thorpej 	isa_bs_w_4,
    123       1.1   thorpej 	bs_notimpl_bs_w_8,
    124       1.1   thorpej 
    125       1.1   thorpej 	/* write multiple */
    126       1.1   thorpej 	isa_bs_wm_1,
    127       1.1   thorpej 	isa_bs_wm_2,
    128       1.1   thorpej 	isa_bs_wm_4,
    129       1.1   thorpej 	bs_notimpl_bs_wm_8,
    130       1.1   thorpej 
    131       1.1   thorpej 	/* write region */
    132       1.1   thorpej 	isa_bs_wr_1,
    133       1.1   thorpej 	isa_bs_wr_2,
    134       1.1   thorpej 	isa_bs_wr_4,
    135       1.1   thorpej 	bs_notimpl_bs_wr_8,
    136       1.1   thorpej 
    137       1.1   thorpej 	/* set multiple */
    138       1.1   thorpej 	bs_notimpl_bs_sm_1,
    139       1.1   thorpej 	bs_notimpl_bs_sm_2,
    140       1.1   thorpej 	bs_notimpl_bs_sm_4,
    141       1.1   thorpej 	bs_notimpl_bs_sm_8,
    142       1.1   thorpej 
    143       1.1   thorpej 	/* set region */
    144       1.1   thorpej 	bs_notimpl_bs_sr_1,
    145       1.1   thorpej 	isa_bs_sr_2,
    146       1.1   thorpej 	bs_notimpl_bs_sr_4,
    147       1.1   thorpej 	bs_notimpl_bs_sr_8,
    148       1.1   thorpej 
    149       1.1   thorpej 	/* copy */
    150       1.1   thorpej 	bs_notimpl_bs_c_1,
    151       1.5   tsutsui 	isa_bs_c_2,
    152       1.1   thorpej 	bs_notimpl_bs_c_4,
    153       1.1   thorpej 	bs_notimpl_bs_c_8,
    154       1.8  macallan 
    155       1.8  macallan 	/* stream methods are identical to regular read/write here */
    156       1.8  macallan 	/* read stream single */
    157       1.8  macallan 	isa_bs_r_1,
    158       1.8  macallan 	isa_bs_r_2,
    159       1.8  macallan 	isa_bs_r_4,
    160       1.8  macallan 	bs_notimpl_bs_r_8,
    161       1.8  macallan 
    162       1.8  macallan 	/* read stream multiple */
    163       1.8  macallan 	isa_bs_rm_1,
    164       1.8  macallan 	isa_bs_rm_2,
    165       1.8  macallan 	isa_bs_rm_4,
    166       1.8  macallan 	bs_notimpl_bs_rm_8,
    167       1.8  macallan 
    168       1.8  macallan 	/* read region stream */
    169       1.8  macallan 	isa_bs_rr_1,
    170       1.8  macallan 	isa_bs_rr_2,
    171       1.8  macallan 	isa_bs_rr_4,
    172       1.8  macallan 	bs_notimpl_bs_rr_8,
    173       1.8  macallan 
    174       1.8  macallan 	/* write stream single */
    175       1.8  macallan 	isa_bs_w_1,
    176       1.8  macallan 	isa_bs_w_2,
    177       1.8  macallan 	isa_bs_w_4,
    178       1.8  macallan 	bs_notimpl_bs_w_8,
    179       1.8  macallan 
    180       1.8  macallan 	/* write stream multiple */
    181       1.8  macallan 	isa_bs_wm_1,
    182       1.8  macallan 	isa_bs_wm_2,
    183       1.8  macallan 	isa_bs_wm_4,
    184       1.8  macallan 	bs_notimpl_bs_wm_8,
    185       1.8  macallan 
    186       1.8  macallan 	/* write region stream */
    187       1.8  macallan 	isa_bs_wr_1,
    188       1.8  macallan 	isa_bs_wr_2,
    189       1.8  macallan 	isa_bs_wr_4,
    190       1.8  macallan 	bs_notimpl_bs_wr_8,
    191       1.8  macallan 
    192       1.1   thorpej };
    193       1.1   thorpej 
    194       1.1   thorpej /*
    195       1.1   thorpej  * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
    196       1.1   thorpej  *       THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY!
    197       1.1   thorpej  */
    198       1.1   thorpej struct bus_space isa_mem_bs_tag = {
    199       1.1   thorpej 	/* cookie */
    200       1.7  macallan         NULL,	/* initialized below */
    201       1.1   thorpej 
    202       1.1   thorpej 	/* mapping/unmapping */
    203       1.1   thorpej 	isa_bs_map,
    204       1.1   thorpej 	isa_bs_unmap,
    205       1.1   thorpej 	isa_bs_subregion,
    206       1.1   thorpej 
    207       1.1   thorpej 	/* allocation/deallocation */
    208       1.1   thorpej 	isa_bs_alloc,
    209       1.1   thorpej 	isa_bs_free,
    210       1.1   thorpej 
    211       1.1   thorpej 	/* get kernel virtual address */
    212       1.1   thorpej 	isa_bs_vaddr,
    213       1.1   thorpej 
    214       1.1   thorpej 	/* mmap bus space for userland */
    215       1.7  macallan 	isa_bs_mmap,
    216       1.1   thorpej 
    217       1.1   thorpej 	/* barrier */
    218       1.1   thorpej 	isa_bs_barrier,
    219       1.1   thorpej 
    220       1.1   thorpej 	/* read (single) */
    221       1.1   thorpej 	isa_bs_r_1,
    222       1.1   thorpej 	isa_bs_r_2,
    223       1.1   thorpej 	isa_bs_r_4,
    224       1.1   thorpej 	bs_notimpl_bs_r_8,
    225       1.1   thorpej 
    226       1.1   thorpej 	/* read multiple */
    227       1.1   thorpej 	isa_bs_rm_1,
    228       1.1   thorpej 	isa_bs_rm_2,
    229       1.1   thorpej 	isa_bs_rm_4,
    230       1.1   thorpej 	bs_notimpl_bs_rm_8,
    231       1.1   thorpej 
    232       1.1   thorpej 	/* read region */
    233       1.1   thorpej 	isa_bs_rr_1,
    234       1.1   thorpej 	isa_bs_rr_2,
    235       1.1   thorpej 	isa_bs_rr_4,
    236       1.1   thorpej 	bs_notimpl_bs_rr_8,
    237       1.1   thorpej 
    238       1.1   thorpej 	/* write (single) */
    239       1.1   thorpej 	isa_bs_w_1,
    240       1.1   thorpej 	isa_bs_w_2,
    241       1.1   thorpej 	isa_bs_w_4,
    242       1.1   thorpej 	bs_notimpl_bs_w_8,
    243       1.1   thorpej 
    244       1.1   thorpej 	/* write multiple */
    245       1.1   thorpej 	isa_bs_wm_1,
    246       1.1   thorpej 	isa_bs_wm_2,
    247       1.1   thorpej 	isa_bs_wm_4,
    248       1.1   thorpej 	bs_notimpl_bs_wm_8,
    249       1.1   thorpej 
    250       1.1   thorpej 	/* write region */
    251       1.1   thorpej 	isa_bs_wr_1,
    252       1.1   thorpej 	isa_bs_wr_2,
    253       1.1   thorpej 	isa_bs_wr_4,
    254       1.1   thorpej 	bs_notimpl_bs_wr_8,
    255       1.1   thorpej 
    256       1.1   thorpej 	/* set multiple */
    257       1.1   thorpej 	bs_notimpl_bs_sm_1,
    258       1.1   thorpej 	bs_notimpl_bs_sm_2,
    259       1.1   thorpej 	bs_notimpl_bs_sm_4,
    260       1.1   thorpej 	bs_notimpl_bs_sm_8,
    261       1.1   thorpej 
    262       1.1   thorpej 	/* set region */
    263       1.1   thorpej 	bs_notimpl_bs_sr_1,
    264       1.1   thorpej 	isa_bs_sr_2,
    265       1.1   thorpej 	bs_notimpl_bs_sr_4,
    266       1.1   thorpej 	bs_notimpl_bs_sr_8,
    267       1.1   thorpej 
    268       1.1   thorpej 	/* copy */
    269       1.1   thorpej 	bs_notimpl_bs_c_1,
    270       1.5   tsutsui 	isa_bs_c_2,
    271       1.1   thorpej 	bs_notimpl_bs_c_4,
    272       1.1   thorpej 	bs_notimpl_bs_c_8,
    273       1.8  macallan 
    274       1.8  macallan 	/* stream methods are identical to regular read/write here */
    275       1.8  macallan 	/* read stream single */
    276       1.8  macallan 	isa_bs_r_1,
    277       1.8  macallan 	isa_bs_r_2,
    278       1.8  macallan 	isa_bs_r_4,
    279       1.8  macallan 	bs_notimpl_bs_r_8,
    280       1.8  macallan 
    281       1.8  macallan 	/* read stream multiple */
    282       1.8  macallan 	isa_bs_rm_1,
    283       1.8  macallan 	isa_bs_rm_2,
    284       1.8  macallan 	isa_bs_rm_4,
    285       1.8  macallan 	bs_notimpl_bs_rm_8,
    286       1.8  macallan 
    287       1.8  macallan 	/* read region stream */
    288       1.8  macallan 	isa_bs_rr_1,
    289       1.8  macallan 	isa_bs_rr_2,
    290       1.8  macallan 	isa_bs_rr_4,
    291       1.8  macallan 	bs_notimpl_bs_rr_8,
    292       1.8  macallan 
    293       1.8  macallan 	/* write stream single */
    294       1.8  macallan 	isa_bs_w_1,
    295       1.8  macallan 	isa_bs_w_2,
    296       1.8  macallan 	isa_bs_w_4,
    297       1.8  macallan 	bs_notimpl_bs_w_8,
    298       1.8  macallan 
    299       1.8  macallan 	/* write stream multiple */
    300       1.8  macallan 	isa_bs_wm_1,
    301       1.8  macallan 	isa_bs_wm_2,
    302       1.8  macallan 	isa_bs_wm_4,
    303       1.8  macallan 	bs_notimpl_bs_wm_8,
    304       1.8  macallan 
    305       1.8  macallan 	/* write region stream */
    306       1.8  macallan 	isa_bs_wr_1,
    307       1.8  macallan 	isa_bs_wr_2,
    308       1.8  macallan 	isa_bs_wr_4,
    309       1.8  macallan 	bs_notimpl_bs_wr_8,
    310       1.1   thorpej };
    311       1.1   thorpej 
    312       1.1   thorpej /* bus space functions */
    313       1.1   thorpej 
    314       1.1   thorpej void
    315       1.9       dsl isa_io_init(vaddr_t isa_io_addr, vaddr_t isa_mem_addr)
    316       1.1   thorpej {
    317       1.1   thorpej 	isa_io_bs_tag.bs_cookie = (void *)isa_io_addr;
    318       1.1   thorpej 	isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr;
    319       1.1   thorpej }
    320       1.1   thorpej 
    321       1.1   thorpej /*
    322       1.1   thorpej  * break the abstraction: sometimes, other parts of the system
    323       1.1   thorpej  * (e.g. X servers) need to map ISA space directly.  use these
    324       1.1   thorpej  * functions sparingly!
    325       1.1   thorpej  */
    326       1.4   tsutsui vaddr_t
    327       1.1   thorpej isa_io_data_vaddr(void)
    328       1.1   thorpej {
    329       1.4   tsutsui 	return (vaddr_t)isa_io_bs_tag.bs_cookie;
    330       1.1   thorpej }
    331       1.1   thorpej 
    332       1.4   tsutsui vaddr_t
    333       1.1   thorpej isa_mem_data_vaddr(void)
    334       1.1   thorpej {
    335       1.4   tsutsui 	return (vaddr_t)isa_mem_bs_tag.bs_cookie;
    336       1.1   thorpej }
    337       1.1   thorpej 
    338       1.1   thorpej int
    339       1.9       dsl isa_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
    340       1.1   thorpej {
    341       1.1   thorpej 	*bshp = bpa + (bus_addr_t)t;
    342       1.1   thorpej 	return(0);
    343       1.1   thorpej }
    344       1.1   thorpej 
    345       1.1   thorpej void
    346       1.9       dsl isa_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    347       1.1   thorpej {
    348       1.1   thorpej 	/* Nothing to do. */
    349       1.1   thorpej }
    350       1.1   thorpej 
    351       1.7  macallan paddr_t
    352       1.7  macallan isa_bs_mmap(void *cookie, bus_addr_t addr, off_t off, int prot,
    353       1.7  macallan     int flags)
    354       1.7  macallan {
    355       1.7  macallan 	paddr_t paddr, ret;
    356       1.7  macallan 
    357       1.7  macallan #ifdef OFISA_DEBUG
    358       1.7  macallan 	printf("mmap %08x %08x %08x", (uint32_t)cookie, (uint32_t)addr, (uint32_t)off);
    359       1.7  macallan #endif
    360       1.7  macallan #if NIGSFB_OFBUS > 0
    361       1.7  macallan 	if ((vaddr_t)cookie == igsfb_mem_vaddr) {
    362       1.7  macallan 		paddr = igsfb_mem_paddr;
    363       1.7  macallan 	} else
    364       1.7  macallan #endif
    365  1.12.6.1  jdolecek #if NCHIPSFB_OFBUS > 0
    366  1.12.6.1  jdolecek 	if ((vaddr_t)cookie == chipsfb_mem_vaddr) {
    367  1.12.6.1  jdolecek 		paddr = 0;
    368  1.12.6.1  jdolecek 	} else
    369  1.12.6.1  jdolecek #endif
    370       1.7  macallan 	paddr = ofw_gettranslation((vaddr_t)cookie);
    371       1.7  macallan 
    372       1.7  macallan 	if (paddr == -1) {
    373       1.7  macallan #ifdef OFISA_DEBUG
    374       1.7  macallan 		printf(" no translation\n");
    375       1.7  macallan #endif
    376       1.7  macallan 		return -1;
    377       1.7  macallan 	}
    378       1.7  macallan 	ret = paddr + addr + off;
    379       1.7  macallan #ifdef OFISA_DEBUG
    380       1.7  macallan 	printf(" -> %08x %08x\n", (uint32_t)paddr, (uint32_t)ret);
    381       1.7  macallan #endif
    382  1.12.6.1  jdolecek 	if (flags & BUS_SPACE_MAP_PREFETCHABLE) {
    383  1.12.6.1  jdolecek 		return (arm_btop(ret) | ARM32_MMAP_WRITECOMBINE);
    384  1.12.6.1  jdolecek 	} else
    385  1.12.6.1  jdolecek 		return arm_btop(ret);
    386       1.7  macallan }
    387       1.7  macallan 
    388       1.1   thorpej int
    389      1.10       dsl isa_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    390       1.1   thorpej {
    391       1.1   thorpej /*	printf("isa_subregion(tag=%p, bsh=%lx, off=%lx, sz=%lx)\n",
    392       1.1   thorpej 	    t, bsh, offset, size);*/
    393       1.1   thorpej 	*nbshp = bsh + offset;
    394       1.1   thorpej 	return(0);
    395       1.1   thorpej }
    396       1.1   thorpej 
    397       1.1   thorpej int
    398      1.12      matt isa_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
    399      1.12      matt 	bus_size_t alignment, bus_size_t boundary, int cacheable,
    400      1.12      matt 	bus_addr_t *bpap, bus_space_handle_t *bshp)
    401       1.1   thorpej {
    402       1.2    provos 	panic("isa_alloc(): Help!");
    403       1.1   thorpej }
    404       1.1   thorpej 
    405       1.1   thorpej void
    406       1.9       dsl isa_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    407       1.1   thorpej {
    408       1.2    provos 	panic("isa_free(): Help!");
    409       1.1   thorpej }
    410       1.1   thorpej 
    411       1.1   thorpej void *
    412       1.9       dsl isa_bs_vaddr(void *t, bus_space_handle_t bsh)
    413       1.1   thorpej {
    414       1.1   thorpej 
    415       1.1   thorpej 	return ((void *)bsh);
    416       1.1   thorpej }
    417       1.1   thorpej 
    418       1.1   thorpej void
    419      1.10       dsl isa_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
    420       1.1   thorpej {
    421       1.1   thorpej 	/* just return */
    422       1.1   thorpej }
    423