Home | History | Annotate | Line # | Download | only in footbridge
footbridge_io.c revision 1.21.10.1
      1  1.21.10.1    rmind /*	$NetBSD: footbridge_io.c,v 1.21.10.1 2014/05/18 17:44:57 rmind Exp $	*/
      2        1.1    chris 
      3        1.1    chris /*
      4        1.1    chris  * Copyright (c) 1997 Causality Limited
      5        1.1    chris  * Copyright (c) 1997 Mark Brinicombe.
      6        1.1    chris  * All rights reserved.
      7        1.1    chris  *
      8        1.1    chris  * Redistribution and use in source and binary forms, with or without
      9        1.1    chris  * modification, are permitted provided that the following conditions
     10        1.1    chris  * are met:
     11        1.1    chris  * 1. Redistributions of source code must retain the above copyright
     12        1.1    chris  *    notice, this list of conditions and the following disclaimer.
     13        1.1    chris  * 2. Redistributions in binary form must reproduce the above copyright
     14        1.1    chris  *    notice, this list of conditions and the following disclaimer in the
     15        1.1    chris  *    documentation and/or other materials provided with the distribution.
     16        1.1    chris  * 3. All advertising materials mentioning features or use of this software
     17        1.1    chris  *    must display the following acknowledgement:
     18        1.1    chris  *	This product includes software developed by Mark Brinicombe
     19        1.1    chris  *	for the NetBSD Project.
     20        1.1    chris  * 4. The name of the company nor the name of the author may be used to
     21        1.1    chris  *    endorse or promote products derived from this software without specific
     22        1.1    chris  *    prior written permission.
     23        1.1    chris  *
     24        1.1    chris  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     25        1.1    chris  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     26        1.1    chris  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27        1.1    chris  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     28        1.1    chris  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     29        1.1    chris  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     30        1.1    chris  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31        1.1    chris  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32        1.1    chris  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33        1.1    chris  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34        1.1    chris  * SUCH DAMAGE.
     35        1.1    chris  */
     36        1.1    chris 
     37        1.1    chris /*
     38        1.1    chris  * bus_space I/O functions for footbridge
     39        1.1    chris  */
     40        1.8    chris 
     41        1.8    chris #include <sys/cdefs.h>
     42  1.21.10.1    rmind __KERNEL_RCSID(0, "$NetBSD: footbridge_io.c,v 1.21.10.1 2014/05/18 17:44:57 rmind Exp $");
     43        1.1    chris 
     44        1.1    chris #include <sys/param.h>
     45        1.1    chris #include <sys/systm.h>
     46       1.20   dyoung #include <sys/bus.h>
     47        1.5    chris #include <arm/footbridge/footbridge.h>
     48        1.1    chris #include <arm/footbridge/dc21285mem.h>
     49        1.1    chris #include <uvm/uvm_extern.h>
     50        1.1    chris 
     51        1.1    chris /* Proto types for all the bus_space structure functions */
     52        1.1    chris 
     53        1.1    chris bs_protos(footbridge);
     54        1.6  thorpej bs_protos(generic);
     55        1.6  thorpej bs_protos(generic_armv4);
     56        1.1    chris bs_protos(bs_notimpl);
     57        1.1    chris bs_map_proto(footbridge_mem);
     58        1.1    chris bs_unmap_proto(footbridge_mem);
     59       1.18    skrll bs_mmap_proto(footbridge_io);
     60       1.13      uwe bs_mmap_proto(footbridge_mem);
     61        1.1    chris 
     62        1.1    chris /* Declare the footbridge bus space tag */
     63        1.1    chris 
     64        1.1    chris struct bus_space footbridge_bs_tag = {
     65        1.1    chris 	/* cookie */
     66        1.1    chris 	(void *) 0,			/* Base address */
     67        1.1    chris 
     68        1.1    chris 	/* mapping/unmapping */
     69        1.1    chris 	footbridge_bs_map,
     70        1.1    chris 	footbridge_bs_unmap,
     71        1.1    chris 	footbridge_bs_subregion,
     72        1.1    chris 
     73        1.1    chris 	/* allocation/deallocation */
     74        1.1    chris 	footbridge_bs_alloc,
     75        1.1    chris 	footbridge_bs_free,
     76        1.1    chris 
     77        1.1    chris 	/* get kernel virtual address */
     78        1.1    chris 	footbridge_bs_vaddr,
     79        1.1    chris 
     80        1.4    chris 	/* Mmap bus space for user */
     81        1.4    chris 	bs_notimpl_bs_mmap,
     82        1.4    chris 
     83        1.1    chris 	/* barrier */
     84        1.1    chris 	footbridge_bs_barrier,
     85        1.1    chris 
     86        1.1    chris 	/* read (single) */
     87        1.6  thorpej 	generic_bs_r_1,
     88        1.6  thorpej 	generic_armv4_bs_r_2,
     89        1.6  thorpej 	generic_bs_r_4,
     90        1.1    chris 	bs_notimpl_bs_r_8,
     91        1.1    chris 
     92        1.1    chris 	/* read multiple */
     93        1.6  thorpej 	generic_bs_rm_1,
     94        1.6  thorpej 	generic_armv4_bs_rm_2,
     95        1.6  thorpej 	generic_bs_rm_4,
     96        1.1    chris 	bs_notimpl_bs_rm_8,
     97        1.1    chris 
     98        1.1    chris 	/* read region */
     99        1.1    chris 	bs_notimpl_bs_rr_1,
    100        1.6  thorpej 	generic_armv4_bs_rr_2,
    101        1.6  thorpej 	generic_bs_rr_4,
    102        1.1    chris 	bs_notimpl_bs_rr_8,
    103        1.1    chris 
    104        1.1    chris 	/* write (single) */
    105        1.6  thorpej 	generic_bs_w_1,
    106        1.6  thorpej 	generic_armv4_bs_w_2,
    107        1.6  thorpej 	generic_bs_w_4,
    108        1.1    chris 	bs_notimpl_bs_w_8,
    109        1.1    chris 
    110        1.1    chris 	/* write multiple */
    111        1.6  thorpej 	generic_bs_wm_1,
    112        1.6  thorpej 	generic_armv4_bs_wm_2,
    113        1.6  thorpej 	generic_bs_wm_4,
    114        1.1    chris 	bs_notimpl_bs_wm_8,
    115        1.1    chris 
    116        1.1    chris 	/* write region */
    117        1.1    chris 	bs_notimpl_bs_wr_1,
    118        1.6  thorpej 	generic_armv4_bs_wr_2,
    119        1.6  thorpej 	generic_bs_wr_4,
    120        1.1    chris 	bs_notimpl_bs_wr_8,
    121        1.1    chris 
    122        1.1    chris 	/* set multiple */
    123        1.1    chris 	bs_notimpl_bs_sm_1,
    124        1.1    chris 	bs_notimpl_bs_sm_2,
    125        1.1    chris 	bs_notimpl_bs_sm_4,
    126        1.1    chris 	bs_notimpl_bs_sm_8,
    127        1.1    chris 
    128        1.1    chris 	/* set region */
    129        1.1    chris 	bs_notimpl_bs_sr_1,
    130        1.6  thorpej 	generic_armv4_bs_sr_2,
    131        1.1    chris 	bs_notimpl_bs_sr_4,
    132        1.1    chris 	bs_notimpl_bs_sr_8,
    133        1.1    chris 
    134        1.1    chris 	/* copy */
    135        1.1    chris 	bs_notimpl_bs_c_1,
    136        1.6  thorpej 	generic_armv4_bs_c_2,
    137        1.1    chris 	bs_notimpl_bs_c_4,
    138        1.1    chris 	bs_notimpl_bs_c_8,
    139        1.1    chris };
    140        1.1    chris 
    141       1.21     matt void
    142       1.21     matt footbridge_create_io_bs_tag(
    143       1.21     matt 	struct bus_space *t,
    144       1.21     matt 	void *cookie)
    145        1.1    chris {
    146        1.1    chris 	*t = footbridge_bs_tag;
    147        1.1    chris 	t->bs_cookie = cookie;
    148       1.18    skrll 	t->bs_mmap = footbridge_io_bs_mmap;
    149        1.1    chris }
    150        1.1    chris 
    151       1.21     matt void
    152       1.21     matt footbridge_create_mem_bs_tag(
    153       1.21     matt 	struct bus_space *t,
    154       1.21     matt 	void *cookie)
    155        1.1    chris {
    156        1.1    chris 	*t = footbridge_bs_tag;
    157        1.1    chris 	t->bs_map = footbridge_mem_bs_map;
    158        1.1    chris 	t->bs_unmap = footbridge_mem_bs_unmap;
    159       1.13      uwe 	t->bs_mmap = footbridge_mem_bs_mmap;
    160        1.1    chris 	t->bs_cookie = cookie;
    161        1.1    chris }
    162        1.1    chris 
    163        1.1    chris /* bus space functions */
    164        1.1    chris 
    165        1.1    chris int
    166       1.15      dsl footbridge_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
    167        1.1    chris {
    168        1.1    chris 	/*
    169        1.1    chris 	 * The whole 64K of PCI space is always completely mapped during
    170        1.1    chris 	 * boot.
    171        1.1    chris 	 *
    172        1.1    chris 	 * Eventually this function will do the mapping check overlapping /
    173        1.1    chris 	 * multiple mappings.
    174        1.1    chris 	 */
    175        1.1    chris 
    176        1.1    chris 	/* The cookie is the base address for the I/O area */
    177        1.1    chris 	*bshp = bpa + (bus_addr_t)t;
    178        1.1    chris 	return(0);
    179        1.1    chris }
    180        1.1    chris 
    181        1.1    chris int
    182  1.21.10.1    rmind footbridge_mem_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
    183  1.21.10.1    rmind     bus_space_handle_t *bshp)
    184        1.1    chris {
    185       1.11    chris 	bus_addr_t startpa, endpa, pa;
    186        1.1    chris 	vaddr_t va;
    187        1.1    chris 
    188        1.1    chris 	/* Round the allocation to page boundries */
    189        1.1    chris 	startpa = trunc_page(bpa);
    190        1.1    chris 	endpa = round_page(bpa + size);
    191        1.1    chris 
    192        1.1    chris 	/*
    193        1.1    chris 	 * Check for mappings below 1MB as we have this space already
    194        1.1    chris 	 * mapped. In practice it is only the VGA hole that takes
    195        1.1    chris 	 * advantage of this.
    196        1.1    chris 	 */
    197        1.1    chris 	if (endpa < DC21285_PCI_ISA_MEM_VSIZE) {
    198        1.1    chris 		/* Store the bus space handle */
    199        1.1    chris 		*bshp = DC21285_PCI_ISA_MEM_VBASE + bpa;
    200        1.1    chris 		return 0;
    201        1.1    chris 	}
    202        1.1    chris 
    203        1.1    chris 	/*
    204        1.1    chris 	 * Eventually this function will do the mapping check for overlapping /
    205        1.1    chris 	 * multiple mappings
    206        1.1    chris 	 */
    207        1.1    chris 
    208       1.12     yamt 	va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
    209       1.12     yamt 	    UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
    210        1.1    chris 	if (va == 0)
    211        1.1    chris 		return ENOMEM;
    212        1.1    chris 
    213        1.1    chris 	/* Store the bus space handle */
    214        1.1    chris 	*bshp = va + (bpa & PGOFSET);
    215        1.1    chris 
    216        1.1    chris 	/* Now map the pages */
    217        1.1    chris 	/* The cookie is the physical base address for the I/O area */
    218  1.21.10.1    rmind 	const int pmapflags =
    219  1.21.10.1    rmind 	    (flags & (BUS_SPACE_MAP_CACHEABLE|BUS_SPACE_MAP_PREFETCHABLE))
    220  1.21.10.1    rmind 		? 0
    221  1.21.10.1    rmind 		: PMAP_NOCACHE;
    222  1.21.10.1    rmind 
    223  1.21.10.1    rmind 	for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
    224  1.21.10.1    rmind 		pmap_kenter_pa(va, (bus_addr_t)t + pa,
    225  1.21.10.1    rmind 		    VM_PROT_READ | VM_PROT_WRITE, pmapflags);
    226       1.17    skrll 	}
    227        1.3    chris 	pmap_update(pmap_kernel());
    228        1.1    chris 
    229        1.1    chris /*	if (bpa >= DC21285_PCI_MEM_VSIZE && bpa != DC21285_ARMCSR_VBASE)
    230        1.7   provos 		panic("footbridge_bs_map: Address out of range (%08lx)", bpa);
    231        1.1    chris */
    232        1.1    chris 	return(0);
    233        1.1    chris }
    234        1.1    chris 
    235        1.1    chris int
    236       1.21     matt footbridge_bs_alloc(
    237       1.21     matt 	void *t,
    238       1.21     matt 	bus_addr_t rstart,
    239       1.21     matt 	bus_addr_t rend,
    240       1.21     matt 	bus_size_t size,
    241       1.21     matt 	bus_size_t alignment,
    242       1.21     matt 	bus_size_t boundary,
    243       1.21     matt 	int cacheable,
    244       1.21     matt 	bus_addr_t *bpap,
    245       1.21     matt 	bus_space_handle_t *bshp)
    246        1.1    chris {
    247        1.7   provos 	panic("footbridge_alloc(): Help!");
    248        1.1    chris }
    249        1.1    chris 
    250        1.1    chris 
    251        1.1    chris void
    252       1.15      dsl footbridge_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    253        1.1    chris {
    254        1.1    chris 	/*
    255        1.1    chris 	 * Temporary implementation
    256        1.1    chris 	 */
    257        1.1    chris }
    258        1.1    chris 
    259        1.1    chris void
    260       1.15      dsl footbridge_mem_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    261        1.1    chris {
    262        1.1    chris 	vaddr_t startva, endva;
    263        1.1    chris 
    264        1.1    chris 	/*
    265        1.1    chris 	 * Check for mappings below 1MB as we have this space permenantly
    266        1.1    chris 	 * mapped. In practice it is only the VGA hole that takes
    267        1.1    chris 	 * advantage of this.
    268        1.1    chris 	 */
    269        1.1    chris 	if (bsh >= DC21285_PCI_ISA_MEM_VBASE
    270        1.1    chris 	    && bsh < (DC21285_PCI_ISA_MEM_VBASE + DC21285_PCI_ISA_MEM_VSIZE)) {
    271        1.1    chris 		return;
    272        1.1    chris 	}
    273        1.1    chris 
    274        1.1    chris 	startva = trunc_page(bsh);
    275        1.1    chris 	endva = round_page(bsh + size);
    276        1.1    chris 
    277  1.21.10.1    rmind 	pmap_kremove(startva, endva);
    278       1.10     yamt 	pmap_update(pmap_kernel());
    279       1.10     yamt 	uvm_km_free(kernel_map, startva, endva - startva, UVM_KMF_VAONLY);
    280        1.1    chris }
    281        1.1    chris 
    282        1.1    chris void
    283       1.15      dsl footbridge_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    284        1.1    chris {
    285        1.1    chris 
    286        1.7   provos 	panic("footbridge_free(): Help!");
    287        1.1    chris 	/* footbridge_bs_unmap() does all that we need to do. */
    288        1.1    chris /*	footbridge_bs_unmap(t, bsh, size);*/
    289        1.1    chris }
    290        1.1    chris 
    291        1.1    chris int
    292       1.15      dsl footbridge_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    293        1.1    chris {
    294        1.1    chris 
    295        1.1    chris 	*nbshp = bsh + (offset << ((int)t));
    296        1.1    chris 	return (0);
    297        1.1    chris }
    298        1.1    chris 
    299        1.1    chris void *
    300       1.15      dsl footbridge_bs_vaddr(void *t, bus_space_handle_t bsh)
    301        1.1    chris {
    302        1.1    chris 
    303        1.1    chris 	return ((void *)bsh);
    304        1.1    chris }
    305        1.1    chris 
    306        1.1    chris void
    307       1.15      dsl footbridge_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
    308        1.1    chris {
    309        1.1    chris }
    310       1.13      uwe 
    311       1.13      uwe 
    312       1.13      uwe paddr_t
    313       1.18    skrll footbridge_io_bs_mmap(void *t, bus_addr_t addr, off_t offset,
    314       1.18    skrll 		       int prot, int flags)
    315       1.18    skrll {
    316       1.18    skrll 	paddr_t pa;
    317       1.18    skrll 
    318       1.18    skrll 	/* allow mapping of IO space */
    319       1.18    skrll 	if (addr >= DC21285_PCI_IO_SIZE ||
    320       1.18    skrll 	    addr >= DC21285_PCI_IO_SIZE - offset ||
    321       1.18    skrll 	    offset < 0 ||
    322       1.18    skrll 	    offset >= DC21285_PCI_IO_SIZE)
    323       1.18    skrll 		return -1;
    324       1.18    skrll 
    325       1.19    skrll 	pa = DC21285_PCI_IO_BASE + addr + offset;
    326       1.18    skrll 
    327       1.18    skrll 	return arm_btop(pa);
    328       1.18    skrll }
    329       1.18    skrll 
    330       1.18    skrll 
    331       1.18    skrll paddr_t
    332       1.13      uwe footbridge_mem_bs_mmap(void *t, bus_addr_t addr, off_t offset,
    333       1.13      uwe 		       int prot, int flags)
    334       1.13      uwe {
    335       1.13      uwe 	paddr_t pa;
    336       1.13      uwe 
    337       1.13      uwe 	if (addr >= DC21285_PCI_MEM_SIZE
    338       1.13      uwe 	    || offset < 0
    339       1.13      uwe 	    || offset >= DC21285_PCI_MEM_SIZE
    340       1.13      uwe 	    || addr >= DC21285_PCI_MEM_SIZE - offset)
    341       1.13      uwe 		return -1;
    342       1.13      uwe 
    343       1.13      uwe 	pa = DC21285_PCI_MEM_BASE + addr + offset;
    344       1.13      uwe 
    345       1.16    skrll 	return arm_btop(pa);
    346       1.13      uwe }
    347