The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/mips/mips/bus_space_generic.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $    */
    2 /*-
    3  * $Id: bus.h,v 1.6 2007/08/09 11:23:32 katta Exp $
    4  *
    5  * SPDX-License-Identifier: BSD-2-Clause-NetBSD AND BSD-4-Clause
    6  *
    7  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
    8  * All rights reserved.
    9  *
   10  * This code is derived from software contributed to The NetBSD Foundation
   11  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
   12  * NASA Ames Research Center.
   13  *
   14  * Redistribution and use in source and binary forms, with or without
   15  * modification, are permitted provided that the following conditions
   16  * are met:
   17  * 1. Redistributions of source code must retain the above copyright
   18  *    notice, this list of conditions and the following disclaimer.
   19  * 2. Redistributions in binary form must reproduce the above copyright
   20  *    notice, this list of conditions and the following disclaimer in the
   21  *    documentation and/or other materials provided with the distribution.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33  * POSSIBILITY OF SUCH DAMAGE.
   34  */
   35 
   36 /*
   37  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
   38  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
   39  *
   40  * Redistribution and use in source and binary forms, with or without
   41  * modification, are permitted provided that the following conditions
   42  * are met:
   43  * 1. Redistributions of source code must retain the above copyright
   44  *    notice, this list of conditions and the following disclaimer.
   45  * 2. Redistributions in binary form must reproduce the above copyright
   46  *    notice, this list of conditions and the following disclaimer in the
   47  *    documentation and/or other materials provided with the distribution.
   48  * 3. All advertising materials mentioning features or use of this software
   49  *    must display the following acknowledgement:
   50  *      This product includes software developed by Christopher G. Demetriou
   51  *      for the NetBSD Project.
   52  * 4. The name of the author may not be used to endorse or promote products
   53  *    derived from this software without specific prior written permission
   54  *
   55  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   56  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   57  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   58  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   59  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   60  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   61  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   62  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   63  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   64  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   65  *
   66  *      from: src/sys/alpha/include/bus.h,v 1.5 1999/08/28 00:38:40 peter
   67  * $FreeBSD: stable/12/sys/mips/mips/bus_space_generic.c 326259 2017-11-27 15:07:26Z pfg $
   68  */
   69 #include <sys/cdefs.h>
   70 __FBSDID("$FreeBSD: stable/12/sys/mips/mips/bus_space_generic.c 326259 2017-11-27 15:07:26Z pfg $");
   71 
   72 #include <sys/param.h>
   73 #include <sys/systm.h>
   74 #include <sys/bus.h>
   75 #include <sys/kernel.h>
   76 #include <sys/malloc.h>
   77 #include <sys/ktr.h>
   78 
   79 #include <vm/vm.h>
   80 #include <vm/pmap.h>
   81 #include <vm/vm_kern.h>
   82 #include <vm/vm_extern.h>
   83 
   84 #include <machine/bus.h>
   85 #include <machine/cache.h>
   86 
   87 static struct bus_space generic_space = {
   88         /* cookie */
   89         .bs_cookie =    (void *) 0,
   90 
   91         /* mapping/unmapping */
   92         .bs_map =       generic_bs_map,
   93         .bs_unmap =     generic_bs_unmap,
   94         .bs_subregion = generic_bs_subregion,
   95 
   96         /* allocation/deallocation */
   97         .bs_alloc =     generic_bs_alloc,
   98         .bs_free =      generic_bs_free,
   99 
  100         /* barrier */
  101         .bs_barrier =   generic_bs_barrier,
  102 
  103         /* read (single) */
  104         .bs_r_1 =       generic_bs_r_1,
  105         .bs_r_2 =       generic_bs_r_2,
  106         .bs_r_4 =       generic_bs_r_4,
  107         .bs_r_8 =       generic_bs_r_8,
  108 
  109         /* read multiple */
  110         .bs_rm_1 =      generic_bs_rm_1,
  111         .bs_rm_2 =      generic_bs_rm_2,
  112         .bs_rm_4 =      generic_bs_rm_4,
  113         .bs_rm_8 =      generic_bs_rm_8,
  114 
  115         /* read region */
  116         .bs_rr_1 =      generic_bs_rr_1,
  117         .bs_rr_2 =      generic_bs_rr_2,
  118         .bs_rr_4 =      generic_bs_rr_4,
  119         .bs_rr_8 =      generic_bs_rr_8,
  120 
  121         /* write (single) */
  122         .bs_w_1 =       generic_bs_w_1,
  123         .bs_w_2 =       generic_bs_w_2,
  124         .bs_w_4 =       generic_bs_w_4,
  125         .bs_w_8 =       generic_bs_w_8,
  126 
  127         /* write multiple */
  128         .bs_wm_1 =      generic_bs_wm_1,
  129         .bs_wm_2 =      generic_bs_wm_2,
  130         .bs_wm_4 =      generic_bs_wm_4,
  131         .bs_wm_8 =      generic_bs_wm_8,
  132 
  133         /* write region */
  134         .bs_wr_1 =      generic_bs_wr_1,
  135         .bs_wr_2 =      generic_bs_wr_2,
  136         .bs_wr_4 =      generic_bs_wr_4,
  137         .bs_wr_8 =      generic_bs_wr_8,
  138 
  139         /* set multiple */
  140         .bs_sm_1 =      generic_bs_sm_1,
  141         .bs_sm_2 =      generic_bs_sm_2,
  142         .bs_sm_4 =      generic_bs_sm_4,
  143         .bs_sm_8 =      generic_bs_sm_8,
  144 
  145         /* set region */
  146         .bs_sr_1 =      generic_bs_sr_1,
  147         .bs_sr_2 =      generic_bs_sr_2,
  148         .bs_sr_4 =      generic_bs_sr_4,
  149         .bs_sr_8 =      generic_bs_sr_8,
  150 
  151         /* copy */
  152         .bs_c_1 =       generic_bs_c_1,
  153         .bs_c_2 =       generic_bs_c_2,
  154         .bs_c_4 =       generic_bs_c_4,
  155         .bs_c_8 =       generic_bs_c_8,
  156 
  157         /* read (single) stream */
  158         .bs_r_1_s =     generic_bs_r_1,
  159         .bs_r_2_s =     generic_bs_r_2,
  160         .bs_r_4_s =     generic_bs_r_4,
  161         .bs_r_8_s =     generic_bs_r_8,
  162 
  163         /* read multiple stream */
  164         .bs_rm_1_s =    generic_bs_rm_1,
  165         .bs_rm_2_s =    generic_bs_rm_2,
  166         .bs_rm_4_s =    generic_bs_rm_4,
  167         .bs_rm_8_s =    generic_bs_rm_8,
  168 
  169         /* read region stream */
  170         .bs_rr_1_s =    generic_bs_rr_1,
  171         .bs_rr_2_s =    generic_bs_rr_2,
  172         .bs_rr_4_s =    generic_bs_rr_4,
  173         .bs_rr_8_s =    generic_bs_rr_8,
  174 
  175         /* write (single) stream */
  176         .bs_w_1_s =     generic_bs_w_1,
  177         .bs_w_2_s =     generic_bs_w_2,
  178         .bs_w_4_s =     generic_bs_w_4,
  179         .bs_w_8_s =     generic_bs_w_8,
  180 
  181         /* write multiple stream */
  182         .bs_wm_1_s =    generic_bs_wm_1,
  183         .bs_wm_2_s =    generic_bs_wm_2,
  184         .bs_wm_4_s =    generic_bs_wm_4,
  185         .bs_wm_8_s =    generic_bs_wm_8,
  186 
  187         /* write region stream */
  188         .bs_wr_1_s =    generic_bs_wr_1,
  189         .bs_wr_2_s =    generic_bs_wr_2,
  190         .bs_wr_4_s =    generic_bs_wr_4,
  191         .bs_wr_8_s =    generic_bs_wr_8,
  192 };
  193 
  194 /* Ultra-gross kludge */
  195 #if defined(CPU_CNMIPS) && (defined(__mips_n32) || defined(__mips_o32))
  196 #include <contrib/octeon-sdk/cvmx.h>
  197 #define rd8(a) cvmx_read64_uint8(a)
  198 #define rd16(a) cvmx_read64_uint16(a)
  199 #define rd32(a) cvmx_read64_uint32(a)
  200 #define rd64(a) cvmx_read64_uint64(a)
  201 #define wr8(a, v) cvmx_write64_uint8(a, v)
  202 #define wr16(a, v) cvmx_write64_uint16(a, v)
  203 #define wr32(a, v) cvmx_write64_uint32(a, v)
  204 #define wr64(a, v) cvmx_write64_uint64(a, v)
  205 #elif defined(CPU_SB1) && _BYTE_ORDER == _BIG_ENDIAN
  206 #include <mips/sibyte/sb_bus_space.h>
  207 #define rd8(a) sb_big_endian_read8(a)
  208 #define rd16(a) sb_big_endian_read16(a)
  209 #define rd32(a) sb_big_endian_read32(a)
  210 #define wr8(a, v) sb_big_endian_write8(a, v)
  211 #define wr16(a, v) sb_big_endian_write16(a, v)
  212 #define wr32(a, v) sb_big_endian_write32(a, v)
  213 #else
  214 #define rd8(a) readb(a)
  215 #define rd16(a) readw(a)
  216 #define rd32(a) readl(a)
  217 #ifdef readq
  218 #define rd64(a) readq((a))
  219 #endif
  220 #define wr8(a, v) writeb(a, v)
  221 #define wr16(a, v) writew(a, v)
  222 #define wr32(a, v) writel(a, v)
  223 #ifdef writeq
  224 #define wr64(a, v) writeq(a, v)
  225 #endif
  226 #endif
  227 
  228 /* generic bus_space tag */
  229 bus_space_tag_t mips_bus_space_generic = &generic_space;
  230 
  231 int
  232 generic_bs_map(void *t __unused, bus_addr_t addr,
  233               bus_size_t size, int flags __unused,
  234               bus_space_handle_t *bshp)
  235 {
  236 
  237         *bshp = (bus_space_handle_t)pmap_mapdev((vm_paddr_t)addr,
  238             (vm_size_t)size);
  239         return (0);
  240 }
  241 
  242 void
  243 generic_bs_unmap(void *t __unused, bus_space_handle_t bh,
  244               bus_size_t size)
  245 {
  246 
  247         pmap_unmapdev((vm_offset_t)bh, (vm_size_t)size);
  248 }
  249 
  250 int
  251 generic_bs_subregion(void *t __unused, bus_space_handle_t handle,
  252               bus_size_t offset, bus_size_t size __unused,
  253               bus_space_handle_t *bshp)
  254 {
  255 
  256         *bshp = handle + offset;
  257         return (0);
  258 }
  259 
  260 int
  261 generic_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
  262     bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
  263     bus_addr_t *bpap, bus_space_handle_t *bshp)
  264 {
  265 
  266         panic("%s: not implemented", __func__);
  267 }
  268 
  269 void    
  270 generic_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
  271 {
  272 
  273         panic("%s: not implemented", __func__);
  274 }
  275 
  276 uint8_t
  277 generic_bs_r_1(void *t, bus_space_handle_t handle,
  278     bus_size_t offset)
  279 {
  280 
  281         return (rd8(handle + offset));
  282 }
  283 
  284 uint16_t
  285 generic_bs_r_2(void *t, bus_space_handle_t handle,
  286     bus_size_t offset)
  287 {
  288 
  289         return (rd16(handle + offset));
  290 }
  291 
  292 uint32_t
  293 generic_bs_r_4(void *t, bus_space_handle_t handle,
  294     bus_size_t offset)
  295 {
  296 
  297         return (rd32(handle + offset));
  298 }
  299 
  300 uint64_t
  301 generic_bs_r_8(void *t, bus_space_handle_t handle, bus_size_t offset)
  302 {
  303 
  304 #ifdef rd64
  305         return(rd64(handle + offset));
  306 #else
  307         panic("%s: not implemented", __func__);
  308 #endif
  309 }
  310 
  311 void
  312 generic_bs_rm_1(void *t, bus_space_handle_t bsh,
  313     bus_size_t offset, uint8_t *addr, size_t count)
  314 {
  315 
  316         while (count--)
  317                 *addr++ = rd8(bsh + offset);
  318 }
  319 
  320 void
  321 generic_bs_rm_2(void *t, bus_space_handle_t bsh,
  322     bus_size_t offset, uint16_t *addr, size_t count)
  323 {
  324         bus_addr_t baddr = bsh + offset;
  325 
  326         while (count--)
  327                 *addr++ = rd16(baddr);
  328 }
  329 
  330 void
  331 generic_bs_rm_4(void *t, bus_space_handle_t bsh,
  332     bus_size_t offset, uint32_t *addr, size_t count)
  333 {
  334         bus_addr_t baddr = bsh + offset;
  335 
  336         while (count--)
  337                 *addr++ = rd32(baddr);
  338 }
  339 
  340 void
  341 generic_bs_rm_8(void *t, bus_space_handle_t bsh, bus_size_t offset,
  342     uint64_t *addr, size_t count)
  343 {
  344 #ifdef rd64
  345         bus_addr_t baddr = bsh + offset;
  346 
  347         while (count--)
  348                 *addr++ = rd64(baddr);
  349 #else
  350         panic("%s: not implemented", __func__);
  351 #endif
  352 }
  353 
  354 /*
  355  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
  356  * described by tag/handle and starting at `offset' and copy into
  357  * buffer provided.
  358  */
  359 void
  360 generic_bs_rr_1(void *t, bus_space_handle_t bsh,
  361     bus_size_t offset, uint8_t *addr, size_t count)
  362 {
  363         bus_addr_t baddr = bsh + offset;
  364 
  365         while (count--) {
  366                 *addr++ = rd8(baddr);
  367                 baddr += 1;
  368         }
  369 }
  370 
  371 void
  372 generic_bs_rr_2(void *t, bus_space_handle_t bsh,
  373     bus_size_t offset, uint16_t *addr, size_t count)
  374 {
  375         bus_addr_t baddr = bsh + offset;
  376 
  377         while (count--) {
  378                 *addr++ = rd16(baddr);
  379                 baddr += 2;
  380         }
  381 }
  382 
  383 void
  384 generic_bs_rr_4(void *t, bus_space_handle_t bsh,
  385     bus_size_t offset, uint32_t *addr, size_t count)
  386 {
  387         bus_addr_t baddr = bsh + offset;
  388 
  389         while (count--) {
  390                 *addr++ = rd32(baddr);
  391                 baddr += 4;
  392         }
  393 }
  394 
  395 void
  396 generic_bs_rr_8(void *t, bus_space_handle_t bsh, bus_size_t offset,
  397     uint64_t *addr, size_t count)
  398 {
  399 #ifdef rd64
  400         bus_addr_t baddr = bsh + offset;
  401 
  402         while (count--) {
  403                 *addr++ = rd64(baddr);
  404                 baddr += 8;
  405         }
  406 #else
  407         panic("%s: not implemented", __func__);
  408 #endif
  409 }
  410 
  411 /*
  412  * Write the 1, 2, 4, or 8 byte value `value' to bus space
  413  * described by tag/handle/offset.
  414  */
  415 void
  416 generic_bs_w_1(void *t, bus_space_handle_t bsh,
  417     bus_size_t offset, uint8_t value)
  418 {
  419 
  420         wr8(bsh + offset, value);
  421 }
  422 
  423 void
  424 generic_bs_w_2(void *t, bus_space_handle_t bsh,
  425     bus_size_t offset, uint16_t value)
  426 {
  427 
  428         wr16(bsh + offset, value);
  429 }
  430 
  431 void
  432 generic_bs_w_4(void *t, bus_space_handle_t bsh,
  433     bus_size_t offset, uint32_t value)
  434 {
  435 
  436         wr32(bsh + offset, value);
  437 }
  438 
  439 void
  440 generic_bs_w_8(void *t, bus_space_handle_t bsh, bus_size_t offset,
  441     uint64_t value)
  442 {
  443 
  444 #ifdef wr64
  445         wr64(bsh + offset, value);
  446 #else
  447         panic("%s: not implemented", __func__);
  448 #endif
  449 }
  450 
  451 /*
  452  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
  453  * provided to bus space described by tag/handle/offset.
  454  */
  455 void
  456 generic_bs_wm_1(void *t, bus_space_handle_t bsh,
  457     bus_size_t offset, const uint8_t *addr, size_t count)
  458 {
  459         bus_addr_t baddr = bsh + offset;
  460 
  461         while (count--)
  462                 wr8(baddr, *addr++);
  463 }
  464 
  465 void
  466 generic_bs_wm_2(void *t, bus_space_handle_t bsh,
  467     bus_size_t offset, const uint16_t *addr, size_t count)
  468 {
  469         bus_addr_t baddr = bsh + offset;
  470 
  471         while (count--)
  472                 wr16(baddr, *addr++);
  473 }
  474 
  475 void
  476 generic_bs_wm_4(void *t, bus_space_handle_t bsh,
  477     bus_size_t offset, const uint32_t *addr, size_t count)
  478 {
  479         bus_addr_t baddr = bsh + offset;
  480 
  481         while (count--)
  482                 wr32(baddr, *addr++);
  483 }
  484 
  485 void
  486 generic_bs_wm_8(void *t, bus_space_handle_t bsh, bus_size_t offset,
  487     const uint64_t *addr, size_t count)
  488 {
  489 #ifdef wr64
  490         bus_addr_t baddr = bsh + offset;
  491 
  492         while (count--)
  493                 wr64(baddr, *addr++);
  494 #else
  495         panic("%s: not implemented", __func__);
  496 #endif
  497 }
  498 
  499 /*
  500  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
  501  * to bus space described by tag/handle starting at `offset'.
  502  */
  503 void
  504 generic_bs_wr_1(void *t, bus_space_handle_t bsh,
  505     bus_size_t offset, const uint8_t *addr, size_t count)
  506 {
  507         bus_addr_t baddr = bsh + offset;
  508 
  509         while (count--) {
  510                 wr8(baddr, *addr++);
  511                 baddr += 1;
  512         }
  513 }
  514 
  515 void
  516 generic_bs_wr_2(void *t, bus_space_handle_t bsh,
  517     bus_size_t offset, const uint16_t *addr, size_t count)
  518 {
  519         bus_addr_t baddr = bsh + offset;
  520 
  521         while (count--) {
  522                 wr16(baddr, *addr++);
  523                 baddr += 2;
  524         }
  525 }
  526 
  527 void
  528 generic_bs_wr_4(void *t, bus_space_handle_t bsh,
  529     bus_size_t offset, const uint32_t *addr, size_t count)
  530 {
  531         bus_addr_t baddr = bsh + offset;
  532 
  533         while (count--) {
  534                 wr32(baddr, *addr++);
  535                 baddr += 4;
  536         }
  537 }
  538 
  539 void
  540 generic_bs_wr_8(void *t, bus_space_handle_t bsh, bus_size_t offset,
  541     const uint64_t *addr, size_t count)
  542 {
  543 #ifdef wr64
  544         bus_addr_t baddr = bsh + offset;
  545 
  546         while (count--) {
  547                 wr64(baddr, *addr++);
  548                 baddr += 8;
  549         }
  550 #else
  551         panic("%s: not implemented", __func__);
  552 #endif
  553 }
  554 
  555 /*
  556  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
  557  * by tag/handle/offset `count' times.
  558  */
  559 void
  560 generic_bs_sm_1(void *t, bus_space_handle_t bsh,
  561     bus_size_t offset, uint8_t value, size_t count)
  562 {
  563         bus_addr_t addr = bsh + offset;
  564 
  565         while (count--)
  566                 wr8(addr, value);
  567 }
  568 
  569 void
  570 generic_bs_sm_2(void *t, bus_space_handle_t bsh,
  571     bus_size_t offset, uint16_t value, size_t count)
  572 {
  573         bus_addr_t addr = bsh + offset;
  574 
  575         while (count--)
  576                 wr16(addr, value);
  577 }
  578 
  579 void
  580 generic_bs_sm_4(void *t, bus_space_handle_t bsh,
  581     bus_size_t offset, uint32_t value, size_t count)
  582 {
  583         bus_addr_t addr = bsh + offset;
  584 
  585         while (count--)
  586                 wr32(addr, value);
  587 }
  588 
  589 void
  590 generic_bs_sm_8(void *t, bus_space_handle_t bsh, bus_size_t offset,
  591     uint64_t value, size_t count)
  592 {
  593 #ifdef wr64
  594         bus_addr_t addr = bsh + offset;
  595 
  596         while (count--)
  597                 wr64(addr, value);
  598 #else
  599         panic("%s: not implemented", __func__);
  600 #endif
  601 }
  602 
  603 /*
  604  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
  605  * by tag/handle starting at `offset'.
  606  */
  607 void
  608 generic_bs_sr_1(void *t, bus_space_handle_t bsh,
  609     bus_size_t offset, uint8_t value, size_t count)
  610 {
  611         bus_addr_t addr = bsh + offset;
  612 
  613         for (; count != 0; count--, addr++)
  614                 wr8(addr, value);
  615 }
  616 
  617 void
  618 generic_bs_sr_2(void *t, bus_space_handle_t bsh,
  619                        bus_size_t offset, uint16_t value, size_t count)
  620 {
  621         bus_addr_t addr = bsh + offset;
  622 
  623         for (; count != 0; count--, addr += 2)
  624                 wr16(addr, value);
  625 }
  626 
  627 void
  628 generic_bs_sr_4(void *t, bus_space_handle_t bsh,
  629     bus_size_t offset, uint32_t value, size_t count)
  630 {
  631         bus_addr_t addr = bsh + offset;
  632 
  633         for (; count != 0; count--, addr += 4)
  634                 wr32(addr, value);
  635 }
  636 
  637 void
  638 generic_bs_sr_8(void *t, bus_space_handle_t bsh, bus_size_t offset,
  639     uint64_t value, size_t count)
  640 {
  641 #ifdef wr64
  642         bus_addr_t addr = bsh + offset;
  643 
  644         for (; count != 0; count--, addr += 8)
  645                 wr64(addr, value);
  646 #else
  647         panic("%s: not implemented", __func__);
  648 #endif
  649 }
  650 
  651 /*
  652  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
  653  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
  654  */
  655 void
  656 generic_bs_c_1(void *t, bus_space_handle_t bsh1,
  657     bus_size_t off1, bus_space_handle_t bsh2,
  658     bus_size_t off2, size_t count)
  659 {
  660         bus_addr_t addr1 = bsh1 + off1;
  661         bus_addr_t addr2 = bsh2 + off2;
  662 
  663         if (addr1 >= addr2) {
  664                 /* src after dest: copy forward */
  665                 for (; count != 0; count--, addr1++, addr2++)
  666                         wr8(addr2, rd8(addr1));
  667         } else {
  668                 /* dest after src: copy backwards */
  669                 for (addr1 += (count - 1), addr2 += (count - 1);
  670                     count != 0; count--, addr1--, addr2--)
  671                         wr8(addr2, rd8(addr1));
  672         }
  673 }
  674 
  675 void
  676 generic_bs_c_2(void *t, bus_space_handle_t bsh1,
  677     bus_size_t off1, bus_space_handle_t bsh2,
  678     bus_size_t off2, size_t count)
  679 {
  680         bus_addr_t addr1 = bsh1 + off1;
  681         bus_addr_t addr2 = bsh2 + off2;
  682 
  683         if (addr1 >= addr2) {
  684                 /* src after dest: copy forward */
  685                 for (; count != 0; count--, addr1 += 2, addr2 += 2)
  686                         wr16(addr2, rd16(addr1));
  687         } else {
  688                 /* dest after src: copy backwards */
  689                 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
  690                     count != 0; count--, addr1 -= 2, addr2 -= 2)
  691                         wr16(addr2, rd16(addr1));
  692         }
  693 }
  694 
  695 void
  696 generic_bs_c_4(void *t, bus_space_handle_t bsh1,
  697     bus_size_t off1, bus_space_handle_t bsh2,
  698     bus_size_t off2, size_t count)
  699 {
  700         bus_addr_t addr1 = bsh1 + off1;
  701         bus_addr_t addr2 = bsh2 + off2;
  702 
  703         if (addr1 >= addr2) {
  704                 /* src after dest: copy forward */
  705                 for (; count != 0; count--, addr1 += 4, addr2 += 4)
  706                         wr32(addr2, rd32(addr1));
  707         } else {
  708                 /* dest after src: copy backwards */
  709                 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
  710                     count != 0; count--, addr1 -= 4, addr2 -= 4)
  711                         wr32(addr2, rd32(addr1));
  712         }
  713 }
  714 
  715 void
  716 generic_bs_c_8(void *t, bus_space_handle_t bsh1, bus_size_t off1,
  717     bus_space_handle_t bsh2, bus_size_t off2, size_t count)
  718 {
  719 #if defined(rd64) && defined(wr64)
  720         bus_addr_t addr1 = bsh1 + off1;
  721         bus_addr_t addr2 = bsh2 + off2;
  722 
  723         if (addr1 >= addr2) {
  724                 /* src after dest: copy forward */
  725                 for (; count != 0; count--, addr1 += 8, addr2 += 8)
  726                         wr64(addr2, rd64(addr1));
  727         } else {
  728                 /* dest after src: copy backwards */
  729                 for (addr1 += 8 * (count - 1), addr2 += 8 * (count - 1);
  730                     count != 0; count--, addr1 -= 8, addr2 -= 8)
  731                         wr64(addr2, rd64(addr1));
  732         }
  733 #else
  734         panic("%s: not implemented", __func__);
  735 #endif
  736 }
  737 
  738 void
  739 generic_bs_barrier(void *t __unused, 
  740                 bus_space_handle_t bsh __unused,
  741                 bus_size_t offset __unused, bus_size_t len __unused, 
  742                 int flags)
  743 {
  744 #if 0
  745         if (flags & BUS_SPACE_BARRIER_WRITE)
  746                 mips_dcache_wbinv_all();
  747 #endif
  748         if (flags & BUS_SPACE_BARRIER_READ)
  749                 rmb();
  750         if (flags & BUS_SPACE_BARRIER_WRITE)
  751                 wmb();
  752 }

Cache object: 30f86cbedd805fdbd8e59f2b59a12783


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.