Home | History | Annotate | Line # | Download | only in ifpga
ifpga_io.c revision 1.10.2.1
      1  1.10.2.1      yamt /*	$NetBSD: ifpga_io.c,v 1.10.2.1 2012/04/17 00:06:14 yamt Exp $ */
      2       1.1  rearnsha 
      3       1.1  rearnsha /*
      4       1.1  rearnsha  * Copyright (c) 1997 Causality Limited
      5       1.1  rearnsha  * Copyright (c) 1997 Mark Brinicombe.
      6       1.1  rearnsha  * All rights reserved.
      7       1.1  rearnsha  *
      8       1.1  rearnsha  * Redistribution and use in source and binary forms, with or without
      9       1.1  rearnsha  * modification, are permitted provided that the following conditions
     10       1.1  rearnsha  * are met:
     11       1.1  rearnsha  * 1. Redistributions of source code must retain the above copyright
     12       1.1  rearnsha  *    notice, this list of conditions and the following disclaimer.
     13       1.1  rearnsha  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1  rearnsha  *    notice, this list of conditions and the following disclaimer in the
     15       1.1  rearnsha  *    documentation and/or other materials provided with the distribution.
     16       1.1  rearnsha  * 3. All advertising materials mentioning features or use of this software
     17       1.1  rearnsha  *    must display the following acknowledgement:
     18       1.1  rearnsha  *	This product includes software developed by Mark Brinicombe
     19       1.1  rearnsha  *	for the NetBSD Project.
     20       1.1  rearnsha  * 4. The name of the company nor the name of the author may be used to
     21       1.1  rearnsha  *    endorse or promote products derived from this software without specific
     22       1.1  rearnsha  *    prior written permission.
     23       1.1  rearnsha  *
     24       1.1  rearnsha  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     25       1.1  rearnsha  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     26       1.1  rearnsha  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27       1.1  rearnsha  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     28       1.1  rearnsha  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     29       1.1  rearnsha  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     30       1.1  rearnsha  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31       1.1  rearnsha  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32       1.1  rearnsha  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33       1.1  rearnsha  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34       1.1  rearnsha  * SUCH DAMAGE.
     35       1.1  rearnsha  *
     36       1.1  rearnsha  * From arm/footbridge/footbridge_io.c
     37       1.1  rearnsha  */
     38       1.1  rearnsha 
     39       1.1  rearnsha /*
     40       1.1  rearnsha  * bus_space I/O functions for IFPGA
     41       1.1  rearnsha  */
     42       1.6     lukem 
     43       1.6     lukem #include <sys/cdefs.h>
     44  1.10.2.1      yamt __KERNEL_RCSID(0, "$NetBSD: ifpga_io.c,v 1.10.2.1 2012/04/17 00:06:14 yamt Exp $");
     45       1.1  rearnsha 
     46       1.1  rearnsha #include <sys/param.h>
     47       1.1  rearnsha #include <sys/systm.h>
     48      1.10    dyoung #include <sys/bus.h>
     49       1.1  rearnsha #include <uvm/uvm_extern.h>
     50       1.4   thorpej 
     51       1.4   thorpej #include <evbarm/ifpga/ifpgavar.h>
     52       1.1  rearnsha 
     53       1.1  rearnsha /* Proto types for all the bus_space structure functions */
     54       1.1  rearnsha 
     55       1.1  rearnsha bs_protos(ifpga);
     56       1.2   thorpej bs_protos(generic);
     57       1.2   thorpej bs_protos(generic_armv4);
     58       1.1  rearnsha bs_protos(bs_notimpl);
     59       1.1  rearnsha bs_map_proto(ifpga_mem);
     60       1.1  rearnsha bs_unmap_proto(ifpga_mem);
     61       1.1  rearnsha 
     62       1.1  rearnsha /* Declare the ifpga bus space tag */
     63       1.1  rearnsha 
     64       1.1  rearnsha struct bus_space ifpga_bs_tag = {
     65       1.1  rearnsha 	/* cookie */
     66       1.1  rearnsha 	(void *) 0,			/* Physical base address */
     67       1.1  rearnsha 
     68       1.1  rearnsha 	/* mapping/unmapping */
     69       1.1  rearnsha 	ifpga_bs_map,
     70       1.1  rearnsha 	ifpga_bs_unmap,
     71       1.1  rearnsha 	ifpga_bs_subregion,
     72       1.1  rearnsha 
     73       1.1  rearnsha 	/* allocation/deallocation */
     74       1.1  rearnsha 	ifpga_bs_alloc,
     75       1.1  rearnsha 	ifpga_bs_free,
     76       1.1  rearnsha 
     77       1.1  rearnsha 	/* get kernel virtual address */
     78       1.1  rearnsha 	ifpga_bs_vaddr,
     79       1.1  rearnsha 
     80       1.1  rearnsha 	/* mmap */
     81       1.1  rearnsha 	bs_notimpl_bs_mmap,
     82       1.1  rearnsha 
     83       1.1  rearnsha 	/* barrier */
     84       1.1  rearnsha 	ifpga_bs_barrier,
     85       1.1  rearnsha 
     86       1.1  rearnsha 	/* read (single) */
     87       1.2   thorpej 	generic_bs_r_1,
     88       1.2   thorpej 	generic_armv4_bs_r_2,
     89       1.2   thorpej 	generic_bs_r_4,
     90       1.1  rearnsha 	bs_notimpl_bs_r_8,
     91       1.1  rearnsha 
     92       1.1  rearnsha 	/* read multiple */
     93       1.2   thorpej 	generic_bs_rm_1,
     94       1.2   thorpej 	generic_armv4_bs_rm_2,
     95       1.2   thorpej 	generic_bs_rm_4,
     96       1.1  rearnsha 	bs_notimpl_bs_rm_8,
     97       1.1  rearnsha 
     98       1.1  rearnsha 	/* read region */
     99       1.1  rearnsha 	bs_notimpl_bs_rr_1,
    100       1.2   thorpej 	generic_armv4_bs_rr_2,
    101       1.2   thorpej 	generic_bs_rr_4,
    102       1.1  rearnsha 	bs_notimpl_bs_rr_8,
    103       1.1  rearnsha 
    104       1.1  rearnsha 	/* write (single) */
    105       1.2   thorpej 	generic_bs_w_1,
    106       1.2   thorpej 	generic_armv4_bs_w_2,
    107       1.2   thorpej 	generic_bs_w_4,
    108       1.1  rearnsha 	bs_notimpl_bs_w_8,
    109       1.1  rearnsha 
    110       1.1  rearnsha 	/* write multiple */
    111       1.2   thorpej 	generic_bs_wm_1,
    112       1.2   thorpej 	generic_armv4_bs_wm_2,
    113       1.2   thorpej 	generic_bs_wm_4,
    114       1.1  rearnsha 	bs_notimpl_bs_wm_8,
    115       1.1  rearnsha 
    116       1.1  rearnsha 	/* write region */
    117       1.1  rearnsha 	bs_notimpl_bs_wr_1,
    118       1.2   thorpej 	generic_armv4_bs_wr_2,
    119       1.2   thorpej 	generic_bs_wr_4,
    120       1.1  rearnsha 	bs_notimpl_bs_wr_8,
    121       1.1  rearnsha 
    122       1.1  rearnsha 	/* set multiple */
    123       1.1  rearnsha 	bs_notimpl_bs_sm_1,
    124       1.1  rearnsha 	bs_notimpl_bs_sm_2,
    125       1.1  rearnsha 	bs_notimpl_bs_sm_4,
    126       1.1  rearnsha 	bs_notimpl_bs_sm_8,
    127       1.1  rearnsha 
    128       1.1  rearnsha 	/* set region */
    129       1.1  rearnsha 	bs_notimpl_bs_sr_1,
    130       1.2   thorpej 	generic_armv4_bs_sr_2,
    131       1.1  rearnsha 	bs_notimpl_bs_sr_4,
    132       1.1  rearnsha 	bs_notimpl_bs_sr_8,
    133       1.1  rearnsha 
    134       1.1  rearnsha 	/* copy */
    135       1.1  rearnsha 	bs_notimpl_bs_c_1,
    136       1.2   thorpej 	generic_armv4_bs_c_2,
    137       1.1  rearnsha 	bs_notimpl_bs_c_4,
    138       1.1  rearnsha 	bs_notimpl_bs_c_8,
    139       1.1  rearnsha };
    140       1.1  rearnsha 
    141  1.10.2.1      yamt void
    142  1.10.2.1      yamt ifpga_create_io_bs_tag(struct bus_space *t, void *cookie)
    143       1.1  rearnsha {
    144       1.1  rearnsha 	*t = ifpga_bs_tag;
    145       1.1  rearnsha 	t->bs_cookie = cookie;
    146       1.1  rearnsha }
    147       1.1  rearnsha 
    148  1.10.2.1      yamt void
    149  1.10.2.1      yamt ifpga_create_mem_bs_tag(struct bus_space *t, void *cookie)
    150       1.1  rearnsha {
    151       1.1  rearnsha 	*t = ifpga_bs_tag;
    152       1.1  rearnsha 	t->bs_map = ifpga_mem_bs_map;
    153       1.1  rearnsha 	t->bs_unmap = ifpga_mem_bs_unmap;
    154       1.1  rearnsha 	t->bs_cookie = cookie;
    155       1.1  rearnsha }
    156       1.1  rearnsha 
    157       1.1  rearnsha /* bus space functions */
    158       1.1  rearnsha 
    159       1.1  rearnsha int
    160       1.9       dsl ifpga_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
    161       1.1  rearnsha {
    162       1.1  rearnsha         /* The cookie is the base address for the I/O area */
    163       1.1  rearnsha         *bshp = bpa + (bus_addr_t)t;
    164       1.1  rearnsha 	return 0;
    165       1.1  rearnsha }
    166       1.1  rearnsha 
    167       1.1  rearnsha int
    168       1.9       dsl ifpga_mem_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
    169       1.1  rearnsha {
    170       1.1  rearnsha 	bus_addr_t startpa, endpa;
    171       1.1  rearnsha 	vaddr_t va;
    172       1.1  rearnsha 
    173       1.1  rearnsha 	/* Round the allocation to page boundries */
    174       1.1  rearnsha 	startpa = trunc_page(bpa);
    175       1.1  rearnsha 	endpa = round_page(bpa + size);
    176       1.1  rearnsha 
    177       1.1  rearnsha 	/* Get some VM.  */
    178       1.8      yamt 	va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
    179       1.8      yamt 	    UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
    180       1.1  rearnsha 	if (va == 0)
    181       1.1  rearnsha 		return ENOMEM;
    182       1.1  rearnsha 
    183       1.1  rearnsha 	/* Store the bus space handle */
    184       1.1  rearnsha 	*bshp = va + (bpa & PGOFSET);
    185       1.1  rearnsha 
    186       1.1  rearnsha 	/* Now map the pages */
    187       1.1  rearnsha 	/* The cookie is the physical base address for the I/O area */
    188       1.1  rearnsha 	while (startpa < endpa) {
    189       1.1  rearnsha 		/* XXX pmap_kenter_pa maps pages cacheable -- not what
    190       1.1  rearnsha 		   we want.  */
    191       1.1  rearnsha 		pmap_enter(pmap_kernel(), va, (bus_addr_t)t + startpa,
    192       1.1  rearnsha 			   VM_PROT_READ | VM_PROT_WRITE, 0);
    193       1.5   thorpej 		va += PAGE_SIZE;
    194       1.5   thorpej 		startpa += PAGE_SIZE;
    195       1.1  rearnsha 	}
    196       1.1  rearnsha 	pmap_update(pmap_kernel());
    197       1.1  rearnsha 
    198       1.1  rearnsha 	return 0;
    199       1.1  rearnsha }
    200       1.1  rearnsha 
    201       1.1  rearnsha int
    202  1.10.2.1      yamt ifpga_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
    203  1.10.2.1      yamt 	bus_size_t alignment, bus_size_t boundary, int cacheable,
    204  1.10.2.1      yamt 	bus_addr_t *bpap, bus_space_handle_t *bshp)
    205       1.1  rearnsha {
    206       1.3    provos 	panic("ifpga_alloc(): Help!");
    207       1.1  rearnsha }
    208       1.1  rearnsha 
    209       1.1  rearnsha 
    210       1.1  rearnsha void
    211       1.9       dsl ifpga_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    212       1.1  rearnsha {
    213       1.1  rearnsha 	/* Nothing to do for an io map.  */
    214       1.1  rearnsha }
    215       1.1  rearnsha 
    216       1.1  rearnsha void
    217       1.9       dsl ifpga_mem_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    218       1.1  rearnsha {
    219       1.1  rearnsha 	vaddr_t startva, endva;
    220       1.1  rearnsha 
    221       1.1  rearnsha 	startva = trunc_page(bsh);
    222       1.1  rearnsha 	endva = round_page(bsh + size);
    223       1.1  rearnsha 
    224       1.7      yamt 	pmap_remove(pmap_kernel(), startva, endva);
    225       1.7      yamt 	pmap_update(pmap_kernel());
    226       1.7      yamt 	uvm_km_free(kernel_map, startva, endva - startva, UVM_KMF_VAONLY);
    227       1.1  rearnsha }
    228       1.1  rearnsha 
    229       1.1  rearnsha void
    230       1.9       dsl ifpga_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    231       1.1  rearnsha {
    232       1.1  rearnsha 
    233       1.3    provos 	panic("ifpga_free(): Help!");
    234       1.1  rearnsha 	/* ifpga_bs_unmap() does all that we need to do. */
    235       1.1  rearnsha /*	ifpga_bs_unmap(t, bsh, size);*/
    236       1.1  rearnsha }
    237       1.1  rearnsha 
    238       1.1  rearnsha int
    239       1.9       dsl ifpga_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    240       1.1  rearnsha {
    241       1.1  rearnsha 
    242       1.1  rearnsha 	*nbshp = bsh + (offset << ((int)t));
    243       1.1  rearnsha 	return (0);
    244       1.1  rearnsha }
    245       1.1  rearnsha 
    246       1.1  rearnsha void *
    247       1.9       dsl ifpga_bs_vaddr(void *t, bus_space_handle_t bsh)
    248       1.1  rearnsha {
    249       1.1  rearnsha 
    250       1.1  rearnsha 	return ((void *)bsh);
    251       1.1  rearnsha }
    252       1.1  rearnsha 
    253       1.1  rearnsha void
    254       1.9       dsl ifpga_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
    255       1.1  rearnsha {
    256       1.1  rearnsha }
    257