Home | History | Annotate | Line # | Download | only in imx
      1 /* $Id: imx23_space.c,v 1.3 2018/03/16 17:56:31 ryo Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2012 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Petri Laakso.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * bus_space(9) support for Freescale i.MX23 processor.
     34  */
     35 
     36 #include <sys/param.h>
     37 #include <sys/bus.h>
     38 #include <sys/mutex.h>
     39 #include <uvm/uvm_prot.h>
     40 #include <machine/pcb.h>
     41 #include <uvm/uvm_pmap.h>
     42 #include <machine/bus_defs.h>
     43 #include <machine/pmap.h>
     44 
     45 
     46 int	imx23_bs_map(void *, bus_addr_t, bus_size_t, int, bus_space_handle_t *);
     47 void	imx23_bs_unmap(void *, bus_space_handle_t, bus_size_t);
     48 int	imx23_bs_subregion(void *, bus_space_handle_t, bus_size_t, bus_size_t,
     49 		bus_space_handle_t *);
     50 int	imx23_bs_alloc(void *, bus_addr_t, bus_addr_t, bus_size_t, bus_size_t,
     51 		bus_size_t, int, bus_addr_t *, bus_space_handle_t *);
     52 void	imx23_bs_free(void *, bus_space_handle_t, bus_size_t);
     53 void *	imx23_bs_vaddr(void *, bus_space_handle_t);
     54 paddr_t	imx23_bs_mmap(void *, bus_addr_t, off_t, int, int);
     55 void	imx23_bs_barrier(void *, bus_space_handle_t, bus_size_t,
     56 		bus_size_t, int);
     57 
     58 bs_protos(bs_notimpl);
     59 bs_protos(generic);
     60 bs_protos(generic_armv4);
     61 
     62 /* Describes bus space on i.MX23 */
     63 struct bus_space imx23_bus_space = {
     64 	/* cookie */
     65 	.bs_cookie = (void *) 0,
     66 
     67 	/* mapping/unmapping */
     68 	.bs_map = imx23_bs_map,
     69 	.bs_unmap = imx23_bs_unmap,
     70 	.bs_subregion = imx23_bs_subregion,
     71 
     72 	/* allocation/deallocation */
     73 	.bs_alloc = imx23_bs_alloc,
     74 	.bs_free = imx23_bs_free,
     75 
     76 	/* get kernel virtual address */
     77 	.bs_vaddr = imx23_bs_vaddr,
     78 
     79 	/* mmap bus space for user */
     80 	.bs_mmap = imx23_bs_mmap,
     81 
     82 	/* barrier */
     83 	.bs_barrier = imx23_bs_barrier,
     84 
     85 	/* read (single) */
     86 	.bs_r_1 = generic_bs_r_1,
     87 	.bs_r_2 = generic_armv4_bs_r_2,
     88 	.bs_r_4 = generic_bs_r_4,
     89 	.bs_r_8 = bs_notimpl_bs_r_8,
     90 
     91 	/* read multiple */
     92 	.bs_rm_1 = generic_bs_rm_1,
     93 	.bs_rm_2 = generic_armv4_bs_rm_2,
     94 	.bs_rm_4 = generic_bs_rm_4,
     95 	.bs_rm_8 = bs_notimpl_bs_rm_8,
     96 
     97 	/* read region */
     98 	.bs_rr_1 = generic_bs_rr_1,
     99 	.bs_rr_2 = generic_armv4_bs_rr_2,
    100 	.bs_rr_4 = generic_bs_rr_4,
    101 	.bs_rr_8 = bs_notimpl_bs_rr_8,
    102 
    103 	/* write (single) */
    104 	.bs_w_1 = generic_bs_w_1,
    105 	.bs_w_2 = generic_armv4_bs_w_2,
    106 	.bs_w_4 = generic_bs_w_4,
    107 	.bs_w_8 = bs_notimpl_bs_w_8,
    108 
    109 	/* write multiple */
    110 	.bs_wm_1 = generic_bs_wm_1,
    111 	.bs_wm_2 = generic_armv4_bs_wm_2,
    112 	.bs_wm_4 = generic_bs_wm_4,
    113 	.bs_wm_8 = bs_notimpl_bs_wm_8,
    114 
    115 	/* write region */
    116 	.bs_wr_1 = generic_bs_wr_1,
    117 	.bs_wr_2 = generic_armv4_bs_wr_2,
    118 	.bs_wr_4 = generic_bs_wr_4,
    119 	.bs_wr_8 = bs_notimpl_bs_wr_8,
    120 
    121 	/* set multiple */
    122 	.bs_sm_1 = bs_notimpl_bs_sm_1,
    123 	.bs_sm_2 = bs_notimpl_bs_sm_2,
    124 	.bs_sm_4 = bs_notimpl_bs_sm_4,
    125 	.bs_sm_8 = bs_notimpl_bs_sm_8,
    126 
    127 	/* set region */
    128 	.bs_sr_1 = generic_bs_sr_1,
    129 	.bs_sr_2 = generic_armv4_bs_sr_2,
    130 	.bs_sr_4 = generic_bs_sr_4,
    131 	.bs_sr_8 = bs_notimpl_bs_sr_8,
    132 
    133 	/* copy */
    134 	.bs_c_1 = bs_notimpl_bs_c_1,
    135 	.bs_c_2 = generic_armv4_bs_c_2,
    136 	.bs_c_4 = bs_notimpl_bs_c_4,
    137 	.bs_c_8 = bs_notimpl_bs_c_8
    138 };
    139 
    140 int
    141 imx23_bs_map(void *space, bus_addr_t address, bus_size_t size,
    142 	int flags, bus_space_handle_t *handlep)
    143 {
    144 	const struct pmap_devmap *pd;
    145 
    146 	if ((pd = pmap_devmap_find_pa(address, size)) != NULL) {
    147 		/* Device was statically mapped. */
    148 		*handlep = pd->pd_va + (address - pd->pd_pa);
    149 		return 0;
    150 	}
    151 
    152 	return 0;
    153 }
    154 
    155 void
    156 imx23_bs_unmap(void *space, bus_space_handle_t handle, bus_size_t size)
    157 {
    158 	if (pmap_devmap_find_va(handle, size) != NULL) {
    159 		/* Device was statically mapped. */
    160 		return;
    161 	}
    162 
    163 	return;
    164 }
    165 
    166 int
    167 imx23_bs_subregion(void *space, bus_space_handle_t handle,
    168 	bus_size_t offset, bus_size_t size, bus_space_handle_t *nhandlep)
    169 {
    170 	*nhandlep = handle + offset;
    171 	return 0;
    172 }
    173 
    174 int
    175 imx23_bs_alloc(void *space, bus_addr_t reg_start, bus_addr_t reg_end,
    176 	bus_size_t size, bus_size_t alignment,
    177 	bus_size_t boundary, int flags, bus_addr_t *addrp,
    178 	bus_space_handle_t *handlep)
    179 {
    180 	return 0;
    181 }
    182 
    183 void
    184 imx23_bs_free(void *space, bus_space_handle_t handle, bus_size_t size)
    185 {
    186 	return;
    187 }
    188 
    189 void *
    190 imx23_bs_vaddr(void *space, bus_space_handle_t handle)
    191 {
    192 	return (void *)0;
    193 }
    194 
    195 paddr_t
    196 imx23_bs_mmap(void *space, bus_addr_t addr, off_t off, int prot,
    197 	int flags)
    198 {
    199 	return (paddr_t)0;
    200 }
    201 
    202 void
    203 imx23_bs_barrier(void *space, bus_space_handle_t handle,
    204 	bus_size_t offset,
    205 	bus_size_t length, int flags)
    206 {
    207 	return;
    208 }
    209