Home | History | Annotate | Line # | Download | only in isa
isa_io.c revision 1.8.64.1
      1  1.8.64.1       jym /*	$NetBSD: isa_io.c,v 1.8.64.1 2009/05/13 17:18:22 jym 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.8.64.1       jym __KERNEL_RCSID(0, "$NetBSD: isa_io.c,v 1.8.64.1 2009/05/13 17:18:22 jym 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.8  macallan 
    147       1.8  macallan 	/* stream methods are identical to regular read/write here */
    148       1.8  macallan 	/* read stream single */
    149       1.8  macallan 	isa_bs_r_1,
    150       1.8  macallan 	isa_bs_r_2,
    151       1.8  macallan 	isa_bs_r_4,
    152       1.8  macallan 	bs_notimpl_bs_r_8,
    153       1.8  macallan 
    154       1.8  macallan 	/* read stream multiple */
    155       1.8  macallan 	isa_bs_rm_1,
    156       1.8  macallan 	isa_bs_rm_2,
    157       1.8  macallan 	isa_bs_rm_4,
    158       1.8  macallan 	bs_notimpl_bs_rm_8,
    159       1.8  macallan 
    160       1.8  macallan 	/* read region stream */
    161       1.8  macallan 	isa_bs_rr_1,
    162       1.8  macallan 	isa_bs_rr_2,
    163       1.8  macallan 	isa_bs_rr_4,
    164       1.8  macallan 	bs_notimpl_bs_rr_8,
    165       1.8  macallan 
    166       1.8  macallan 	/* write stream single */
    167       1.8  macallan 	isa_bs_w_1,
    168       1.8  macallan 	isa_bs_w_2,
    169       1.8  macallan 	isa_bs_w_4,
    170       1.8  macallan 	bs_notimpl_bs_w_8,
    171       1.8  macallan 
    172       1.8  macallan 	/* write stream multiple */
    173       1.8  macallan 	isa_bs_wm_1,
    174       1.8  macallan 	isa_bs_wm_2,
    175       1.8  macallan 	isa_bs_wm_4,
    176       1.8  macallan 	bs_notimpl_bs_wm_8,
    177       1.8  macallan 
    178       1.8  macallan 	/* write region stream */
    179       1.8  macallan 	isa_bs_wr_1,
    180       1.8  macallan 	isa_bs_wr_2,
    181       1.8  macallan 	isa_bs_wr_4,
    182       1.8  macallan 	bs_notimpl_bs_wr_8,
    183       1.8  macallan 
    184       1.1   thorpej };
    185       1.1   thorpej 
    186       1.1   thorpej /*
    187       1.1   thorpej  * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
    188       1.1   thorpej  *       THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY!
    189       1.1   thorpej  */
    190       1.1   thorpej struct bus_space isa_mem_bs_tag = {
    191       1.1   thorpej 	/* cookie */
    192       1.7  macallan         NULL,	/* initialized below */
    193       1.1   thorpej 
    194       1.1   thorpej 	/* mapping/unmapping */
    195       1.1   thorpej 	isa_bs_map,
    196       1.1   thorpej 	isa_bs_unmap,
    197       1.1   thorpej 	isa_bs_subregion,
    198       1.1   thorpej 
    199       1.1   thorpej 	/* allocation/deallocation */
    200       1.1   thorpej 	isa_bs_alloc,
    201       1.1   thorpej 	isa_bs_free,
    202       1.1   thorpej 
    203       1.1   thorpej 	/* get kernel virtual address */
    204       1.1   thorpej 	isa_bs_vaddr,
    205       1.1   thorpej 
    206       1.1   thorpej 	/* mmap bus space for userland */
    207       1.7  macallan 	isa_bs_mmap,
    208       1.1   thorpej 
    209       1.1   thorpej 	/* barrier */
    210       1.1   thorpej 	isa_bs_barrier,
    211       1.1   thorpej 
    212       1.1   thorpej 	/* read (single) */
    213       1.1   thorpej 	isa_bs_r_1,
    214       1.1   thorpej 	isa_bs_r_2,
    215       1.1   thorpej 	isa_bs_r_4,
    216       1.1   thorpej 	bs_notimpl_bs_r_8,
    217       1.1   thorpej 
    218       1.1   thorpej 	/* read multiple */
    219       1.1   thorpej 	isa_bs_rm_1,
    220       1.1   thorpej 	isa_bs_rm_2,
    221       1.1   thorpej 	isa_bs_rm_4,
    222       1.1   thorpej 	bs_notimpl_bs_rm_8,
    223       1.1   thorpej 
    224       1.1   thorpej 	/* read region */
    225       1.1   thorpej 	isa_bs_rr_1,
    226       1.1   thorpej 	isa_bs_rr_2,
    227       1.1   thorpej 	isa_bs_rr_4,
    228       1.1   thorpej 	bs_notimpl_bs_rr_8,
    229       1.1   thorpej 
    230       1.1   thorpej 	/* write (single) */
    231       1.1   thorpej 	isa_bs_w_1,
    232       1.1   thorpej 	isa_bs_w_2,
    233       1.1   thorpej 	isa_bs_w_4,
    234       1.1   thorpej 	bs_notimpl_bs_w_8,
    235       1.1   thorpej 
    236       1.1   thorpej 	/* write multiple */
    237       1.1   thorpej 	isa_bs_wm_1,
    238       1.1   thorpej 	isa_bs_wm_2,
    239       1.1   thorpej 	isa_bs_wm_4,
    240       1.1   thorpej 	bs_notimpl_bs_wm_8,
    241       1.1   thorpej 
    242       1.1   thorpej 	/* write region */
    243       1.1   thorpej 	isa_bs_wr_1,
    244       1.1   thorpej 	isa_bs_wr_2,
    245       1.1   thorpej 	isa_bs_wr_4,
    246       1.1   thorpej 	bs_notimpl_bs_wr_8,
    247       1.1   thorpej 
    248       1.1   thorpej 	/* set multiple */
    249       1.1   thorpej 	bs_notimpl_bs_sm_1,
    250       1.1   thorpej 	bs_notimpl_bs_sm_2,
    251       1.1   thorpej 	bs_notimpl_bs_sm_4,
    252       1.1   thorpej 	bs_notimpl_bs_sm_8,
    253       1.1   thorpej 
    254       1.1   thorpej 	/* set region */
    255       1.1   thorpej 	bs_notimpl_bs_sr_1,
    256       1.1   thorpej 	isa_bs_sr_2,
    257       1.1   thorpej 	bs_notimpl_bs_sr_4,
    258       1.1   thorpej 	bs_notimpl_bs_sr_8,
    259       1.1   thorpej 
    260       1.1   thorpej 	/* copy */
    261       1.1   thorpej 	bs_notimpl_bs_c_1,
    262       1.5   tsutsui 	isa_bs_c_2,
    263       1.1   thorpej 	bs_notimpl_bs_c_4,
    264       1.1   thorpej 	bs_notimpl_bs_c_8,
    265       1.8  macallan 
    266       1.8  macallan 	/* stream methods are identical to regular read/write here */
    267       1.8  macallan 	/* read stream single */
    268       1.8  macallan 	isa_bs_r_1,
    269       1.8  macallan 	isa_bs_r_2,
    270       1.8  macallan 	isa_bs_r_4,
    271       1.8  macallan 	bs_notimpl_bs_r_8,
    272       1.8  macallan 
    273       1.8  macallan 	/* read stream multiple */
    274       1.8  macallan 	isa_bs_rm_1,
    275       1.8  macallan 	isa_bs_rm_2,
    276       1.8  macallan 	isa_bs_rm_4,
    277       1.8  macallan 	bs_notimpl_bs_rm_8,
    278       1.8  macallan 
    279       1.8  macallan 	/* read region stream */
    280       1.8  macallan 	isa_bs_rr_1,
    281       1.8  macallan 	isa_bs_rr_2,
    282       1.8  macallan 	isa_bs_rr_4,
    283       1.8  macallan 	bs_notimpl_bs_rr_8,
    284       1.8  macallan 
    285       1.8  macallan 	/* write stream single */
    286       1.8  macallan 	isa_bs_w_1,
    287       1.8  macallan 	isa_bs_w_2,
    288       1.8  macallan 	isa_bs_w_4,
    289       1.8  macallan 	bs_notimpl_bs_w_8,
    290       1.8  macallan 
    291       1.8  macallan 	/* write stream multiple */
    292       1.8  macallan 	isa_bs_wm_1,
    293       1.8  macallan 	isa_bs_wm_2,
    294       1.8  macallan 	isa_bs_wm_4,
    295       1.8  macallan 	bs_notimpl_bs_wm_8,
    296       1.8  macallan 
    297       1.8  macallan 	/* write region stream */
    298       1.8  macallan 	isa_bs_wr_1,
    299       1.8  macallan 	isa_bs_wr_2,
    300       1.8  macallan 	isa_bs_wr_4,
    301       1.8  macallan 	bs_notimpl_bs_wr_8,
    302       1.1   thorpej };
    303       1.1   thorpej 
    304       1.1   thorpej /* bus space functions */
    305       1.1   thorpej 
    306       1.1   thorpej void
    307  1.8.64.1       jym isa_io_init(vaddr_t isa_io_addr, vaddr_t isa_mem_addr)
    308       1.1   thorpej {
    309       1.1   thorpej 	isa_io_bs_tag.bs_cookie = (void *)isa_io_addr;
    310       1.1   thorpej 	isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr;
    311       1.1   thorpej }
    312       1.1   thorpej 
    313       1.1   thorpej /*
    314       1.1   thorpej  * break the abstraction: sometimes, other parts of the system
    315       1.1   thorpej  * (e.g. X servers) need to map ISA space directly.  use these
    316       1.1   thorpej  * functions sparingly!
    317       1.1   thorpej  */
    318       1.4   tsutsui vaddr_t
    319       1.1   thorpej isa_io_data_vaddr(void)
    320       1.1   thorpej {
    321       1.4   tsutsui 	return (vaddr_t)isa_io_bs_tag.bs_cookie;
    322       1.1   thorpej }
    323       1.1   thorpej 
    324       1.4   tsutsui vaddr_t
    325       1.1   thorpej isa_mem_data_vaddr(void)
    326       1.1   thorpej {
    327       1.4   tsutsui 	return (vaddr_t)isa_mem_bs_tag.bs_cookie;
    328       1.1   thorpej }
    329       1.1   thorpej 
    330       1.1   thorpej int
    331  1.8.64.1       jym isa_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
    332       1.1   thorpej {
    333       1.1   thorpej 	*bshp = bpa + (bus_addr_t)t;
    334       1.1   thorpej 	return(0);
    335       1.1   thorpej }
    336       1.1   thorpej 
    337       1.1   thorpej void
    338  1.8.64.1       jym isa_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    339       1.1   thorpej {
    340       1.1   thorpej 	/* Nothing to do. */
    341       1.1   thorpej }
    342       1.1   thorpej 
    343       1.7  macallan paddr_t
    344       1.7  macallan isa_bs_mmap(void *cookie, bus_addr_t addr, off_t off, int prot,
    345       1.7  macallan     int flags)
    346       1.7  macallan {
    347       1.7  macallan 	paddr_t paddr, ret;
    348       1.7  macallan 
    349       1.7  macallan #ifdef OFISA_DEBUG
    350       1.7  macallan 	printf("mmap %08x %08x %08x", (uint32_t)cookie, (uint32_t)addr, (uint32_t)off);
    351       1.7  macallan #endif
    352       1.7  macallan #if NIGSFB_OFBUS > 0
    353       1.7  macallan 	if ((vaddr_t)cookie == igsfb_mem_vaddr) {
    354       1.7  macallan 		paddr = igsfb_mem_paddr;
    355       1.7  macallan 	} else
    356       1.7  macallan #endif
    357       1.7  macallan 	paddr = ofw_gettranslation((vaddr_t)cookie);
    358       1.7  macallan 
    359       1.7  macallan 	if (paddr == -1) {
    360       1.7  macallan #ifdef OFISA_DEBUG
    361       1.7  macallan 		printf(" no translation\n");
    362       1.7  macallan #endif
    363       1.7  macallan 		return -1;
    364       1.7  macallan 	}
    365       1.7  macallan 	ret = paddr + addr + off;
    366       1.7  macallan #ifdef OFISA_DEBUG
    367       1.7  macallan 	printf(" -> %08x %08x\n", (uint32_t)paddr, (uint32_t)ret);
    368       1.7  macallan #endif
    369       1.7  macallan 	return arm_btop(ret);
    370       1.7  macallan }
    371       1.7  macallan 
    372       1.1   thorpej int
    373  1.8.64.1       jym isa_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    374       1.1   thorpej {
    375       1.1   thorpej /*	printf("isa_subregion(tag=%p, bsh=%lx, off=%lx, sz=%lx)\n",
    376       1.1   thorpej 	    t, bsh, offset, size);*/
    377       1.1   thorpej 	*nbshp = bsh + offset;
    378       1.1   thorpej 	return(0);
    379       1.1   thorpej }
    380       1.1   thorpej 
    381       1.1   thorpej int
    382       1.1   thorpej isa_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
    383       1.1   thorpej     bpap, bshp)
    384       1.1   thorpej 	void *t;
    385       1.1   thorpej 	bus_addr_t rstart, rend;
    386       1.1   thorpej 	bus_size_t size, alignment, boundary;
    387       1.1   thorpej 	int cacheable;
    388       1.1   thorpej 	bus_addr_t *bpap;
    389       1.1   thorpej 	bus_space_handle_t *bshp;
    390       1.1   thorpej {
    391       1.2    provos 	panic("isa_alloc(): Help!");
    392       1.1   thorpej }
    393       1.1   thorpej 
    394       1.1   thorpej void
    395  1.8.64.1       jym isa_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    396       1.1   thorpej {
    397       1.2    provos 	panic("isa_free(): Help!");
    398       1.1   thorpej }
    399       1.1   thorpej 
    400       1.1   thorpej void *
    401  1.8.64.1       jym isa_bs_vaddr(void *t, bus_space_handle_t bsh)
    402       1.1   thorpej {
    403       1.1   thorpej 
    404       1.1   thorpej 	return ((void *)bsh);
    405       1.1   thorpej }
    406       1.1   thorpej 
    407       1.1   thorpej void
    408  1.8.64.1       jym isa_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
    409       1.1   thorpej {
    410       1.1   thorpej 	/* just return */
    411       1.1   thorpej }
    412