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/cavium/octopci_bus_space.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
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  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
    6  * All rights reserved.
    7  *
    8  * This code is derived from software contributed to The NetBSD Foundation
    9  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
   10  * NASA Ames Research Center.
   11  *
   12  * Redistribution and use in source and binary forms, with or without
   13  * modification, are permitted provided that the following conditions
   14  * are met:
   15  * 1. Redistributions of source code must retain the above copyright
   16  *    notice, this list of conditions and the following disclaimer.
   17  * 2. Redistributions in binary form must reproduce the above copyright
   18  *    notice, this list of conditions and the following disclaimer in the
   19  *    documentation and/or other materials provided with the distribution.
   20  * 3. All advertising materials mentioning features or use of this software
   21  *    must display the following acknowledgement:
   22  *      This product includes software developed by the NetBSD
   23  *      Foundation, Inc. and its contributors.
   24  * 4. Neither the name of The NetBSD Foundation nor the names of its
   25  *    contributors may be used to endorse or promote products derived
   26  *    from this software without specific prior written permission.
   27  *
   28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   38  * POSSIBILITY OF SUCH DAMAGE.
   39  */
   40 
   41 /*
   42  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
   43  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
   44  *
   45  * Redistribution and use in source and binary forms, with or without
   46  * modification, are permitted provided that the following conditions
   47  * are met:
   48  * 1. Redistributions of source code must retain the above copyright
   49  *    notice, this list of conditions and the following disclaimer.
   50  * 2. Redistributions in binary form must reproduce the above copyright
   51  *    notice, this list of conditions and the following disclaimer in the
   52  *    documentation and/or other materials provided with the distribution.
   53  * 3. All advertising materials mentioning features or use of this software
   54  *    must display the following acknowledgement:
   55  *      This product includes software developed by Christopher G. Demetriou
   56  *      for the NetBSD Project.
   57  * 4. The name of the author may not be used to endorse or promote products
   58  *    derived from this software without specific prior written permission
   59  *
   60  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   61  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   62  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   63  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   64  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   65  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   66  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   67  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   68  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   69  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   70  *
   71  *      from: src/sys/alpha/include/bus.h,v 1.5 1999/08/28 00:38:40 peter
   72  * $FreeBSD: releng/10.0/sys/mips/cavium/octopci_bus_space.c 232410 2012-03-02 21:46:31Z jmallett $
   73  */
   74 #include <sys/cdefs.h>
   75 __FBSDID("$FreeBSD: releng/10.0/sys/mips/cavium/octopci_bus_space.c 232410 2012-03-02 21:46:31Z jmallett $");
   76 
   77 #include <sys/param.h>
   78 #include <sys/systm.h>
   79 #include <sys/bus.h>
   80 #include <sys/kernel.h>
   81 #include <sys/malloc.h>
   82 #include <sys/ktr.h>
   83 #include <sys/endian.h>
   84 
   85 #include <vm/vm.h>
   86 #include <vm/pmap.h>
   87 #include <vm/vm_kern.h>
   88 #include <vm/vm_extern.h>
   89 
   90 #include <machine/bus.h>
   91 #include <machine/cache.h>
   92 
   93 #include <mips/cavium/octopcivar.h>
   94 
   95 #include <contrib/octeon-sdk/cvmx.h>
   96 
   97 static struct bus_space octopci_space = {
   98         /* cookie */
   99         (void *) 0,
  100 
  101         /* mapping/unmapping */
  102         octopci_bs_map,
  103         octopci_bs_unmap,
  104         octopci_bs_subregion,
  105 
  106         /* allocation/deallocation */
  107         NULL,
  108         NULL,
  109 
  110         /* barrier */
  111         octopci_bs_barrier,
  112 
  113         /* read (single) */
  114         octopci_bs_r_1,
  115         octopci_bs_r_2,
  116         octopci_bs_r_4,
  117         NULL,
  118 
  119         /* read multiple */
  120         octopci_bs_rm_1,
  121         octopci_bs_rm_2,
  122         octopci_bs_rm_4,
  123         NULL,
  124 
  125         /* read region */
  126         octopci_bs_rr_1,
  127         octopci_bs_rr_2,
  128         octopci_bs_rr_4,
  129         NULL,
  130 
  131         /* write (single) */
  132         octopci_bs_w_1,
  133         octopci_bs_w_2,
  134         octopci_bs_w_4,
  135         NULL,
  136 
  137         /* write multiple */
  138         octopci_bs_wm_1,
  139         octopci_bs_wm_2,
  140         octopci_bs_wm_4,
  141         NULL,
  142 
  143         /* write region */
  144         NULL,
  145         octopci_bs_wr_2,
  146         octopci_bs_wr_4,
  147         NULL,
  148 
  149         /* set multiple */
  150         NULL,
  151         NULL,
  152         NULL,
  153         NULL,
  154 
  155         /* set region */
  156         NULL,
  157         octopci_bs_sr_2,
  158         octopci_bs_sr_4,
  159         NULL,
  160 
  161         /* copy */
  162         NULL,
  163         octopci_bs_c_2,
  164         NULL,
  165         NULL,
  166 
  167         /* read (single) stream */
  168         octopci_bs_r_1,
  169         octopci_bs_r_2,
  170         octopci_bs_r_4,
  171         NULL,
  172 
  173         /* read multiple stream */
  174         octopci_bs_rm_1,
  175         octopci_bs_rm_2,
  176         octopci_bs_rm_4,
  177         NULL,
  178 
  179         /* read region stream */
  180         octopci_bs_rr_1,
  181         octopci_bs_rr_2,
  182         octopci_bs_rr_4,
  183         NULL,
  184 
  185         /* write (single) stream */
  186         octopci_bs_w_1,
  187         octopci_bs_w_2,
  188         octopci_bs_w_4,
  189         NULL,
  190 
  191         /* write multiple stream */
  192         octopci_bs_wm_1,
  193         octopci_bs_wm_2,
  194         octopci_bs_wm_4,
  195         NULL,
  196 
  197         /* write region stream */
  198         NULL,
  199         octopci_bs_wr_2,
  200         octopci_bs_wr_4,
  201         NULL,
  202 };
  203 
  204 #define rd8(a)          cvmx_read64_uint8(a)
  205 #define rd16(a)         le16toh(cvmx_read64_uint16(a))
  206 #define rd32(a)         le32toh(cvmx_read64_uint32(a))
  207 #define wr8(a, v)       cvmx_write64_uint8(a, v)
  208 #define wr16(a, v)      cvmx_write64_uint16(a, htole16(v))
  209 #define wr32(a, v)      cvmx_write64_uint32(a, htole32(v))
  210 
  211 /* octopci bus_space tag */
  212 bus_space_tag_t octopci_bus_space = &octopci_space;
  213 
  214 int
  215 octopci_bs_map(void *t __unused, bus_addr_t addr,
  216               bus_size_t size __unused, int flags __unused,
  217               bus_space_handle_t *bshp)
  218 {
  219 
  220         *bshp = addr;
  221         return (0);
  222 }
  223 
  224 void
  225 octopci_bs_unmap(void *t __unused, bus_space_handle_t bh __unused,
  226               bus_size_t size __unused)
  227 {
  228 
  229         /* Do nothing */
  230 }
  231 
  232 int
  233 octopci_bs_subregion(void *t __unused, bus_space_handle_t handle,
  234               bus_size_t offset, bus_size_t size __unused,
  235               bus_space_handle_t *bshp)
  236 {
  237 
  238         *bshp = handle + offset;
  239         return (0);
  240 }
  241 
  242 uint8_t
  243 octopci_bs_r_1(void *t, bus_space_handle_t handle,
  244     bus_size_t offset)
  245 {
  246 
  247         return (rd8(handle + offset));
  248 }
  249 
  250 uint16_t
  251 octopci_bs_r_2(void *t, bus_space_handle_t handle,
  252     bus_size_t offset)
  253 {
  254 
  255         return (rd16(handle + offset));
  256 }
  257 
  258 uint32_t
  259 octopci_bs_r_4(void *t, bus_space_handle_t handle,
  260     bus_size_t offset)
  261 {
  262 
  263         return (rd32(handle + offset));
  264 }
  265 
  266 
  267 void
  268 octopci_bs_rm_1(void *t, bus_space_handle_t bsh,
  269     bus_size_t offset, uint8_t *addr, size_t count)
  270 {
  271 
  272         while (count--)
  273                 *addr++ = rd8(bsh + offset);
  274 }
  275 
  276 void
  277 octopci_bs_rm_2(void *t, bus_space_handle_t bsh,
  278     bus_size_t offset, uint16_t *addr, size_t count)
  279 {
  280         bus_addr_t baddr = bsh + offset;
  281 
  282         while (count--)
  283                 *addr++ = rd16(baddr);
  284 }
  285 
  286 void
  287 octopci_bs_rm_4(void *t, bus_space_handle_t bsh,
  288     bus_size_t offset, uint32_t *addr, size_t count)
  289 {
  290         bus_addr_t baddr = bsh + offset;
  291 
  292         while (count--)
  293                 *addr++ = rd32(baddr);
  294 }
  295 
  296 
  297 /*
  298  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
  299  * described by tag/handle and starting at `offset' and copy into
  300  * buffer provided.
  301  */
  302 void
  303 octopci_bs_rr_1(void *t, bus_space_handle_t bsh,
  304     bus_size_t offset, uint8_t *addr, size_t count)
  305 {
  306         bus_addr_t baddr = bsh + offset;
  307 
  308         while (count--) {
  309                 *addr++ = rd8(baddr);
  310                 baddr += 1;
  311         }
  312 }
  313 
  314 void
  315 octopci_bs_rr_2(void *t, bus_space_handle_t bsh,
  316     bus_size_t offset, uint16_t *addr, size_t count)
  317 {
  318         bus_addr_t baddr = bsh + offset;
  319 
  320         while (count--) {
  321                 *addr++ = rd16(baddr);
  322                 baddr += 2;
  323         }
  324 }
  325 
  326 void
  327 octopci_bs_rr_4(void *t, bus_space_handle_t bsh,
  328     bus_size_t offset, uint32_t *addr, size_t count)
  329 {
  330         bus_addr_t baddr = bsh + offset;
  331 
  332         while (count--) {
  333                 *addr++ = rd32(baddr);
  334                 baddr += 4;
  335         }
  336 }
  337 
  338 /*
  339  * Write the 1, 2, 4, or 8 byte value `value' to bus space
  340  * described by tag/handle/offset.
  341  */
  342 void
  343 octopci_bs_w_1(void *t, bus_space_handle_t bsh,
  344     bus_size_t offset, uint8_t value)
  345 {
  346 
  347         wr8(bsh + offset, value);
  348 }
  349 
  350 void
  351 octopci_bs_w_2(void *t, bus_space_handle_t bsh,
  352     bus_size_t offset, uint16_t value)
  353 {
  354 
  355         wr16(bsh + offset, value);
  356 }
  357 
  358 void
  359 octopci_bs_w_4(void *t, bus_space_handle_t bsh,
  360     bus_size_t offset, uint32_t value)
  361 {
  362 
  363         wr32(bsh + offset, value);
  364 }
  365 
  366 /*
  367  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
  368  * provided to bus space described by tag/handle/offset.
  369  */
  370 void
  371 octopci_bs_wm_1(void *t, bus_space_handle_t bsh,
  372     bus_size_t offset, const uint8_t *addr, size_t count)
  373 {
  374         bus_addr_t baddr = bsh + offset;
  375 
  376         while (count--)
  377                 wr8(baddr, *addr++);
  378 }
  379 
  380 void
  381 octopci_bs_wm_2(void *t, bus_space_handle_t bsh,
  382     bus_size_t offset, const uint16_t *addr, size_t count)
  383 {
  384         bus_addr_t baddr = bsh + offset;
  385 
  386         while (count--)
  387                 wr16(baddr, *addr++);
  388 }
  389 
  390 void
  391 octopci_bs_wm_4(void *t, bus_space_handle_t bsh,
  392     bus_size_t offset, const uint32_t *addr, size_t count)
  393 {
  394         bus_addr_t baddr = bsh + offset;
  395 
  396         while (count--)
  397                 wr32(baddr, *addr++);
  398 }
  399 
  400 /*
  401  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
  402  * to bus space described by tag/handle starting at `offset'.
  403  */
  404 void
  405 octopci_bs_wr_1(void *t, bus_space_handle_t bsh,
  406     bus_size_t offset, const uint8_t *addr, size_t count)
  407 {
  408         bus_addr_t baddr = bsh + offset;
  409 
  410         while (count--) {
  411                 wr8(baddr, *addr++);
  412                 baddr += 1;
  413         }
  414 }
  415 
  416 void
  417 octopci_bs_wr_2(void *t, bus_space_handle_t bsh,
  418     bus_size_t offset, const uint16_t *addr, size_t count)
  419 {
  420         bus_addr_t baddr = bsh + offset;
  421 
  422         while (count--) {
  423                 wr16(baddr, *addr++);
  424                 baddr += 2;
  425         }
  426 }
  427 
  428 void
  429 octopci_bs_wr_4(void *t, bus_space_handle_t bsh,
  430     bus_size_t offset, const uint32_t *addr, size_t count)
  431 {
  432         bus_addr_t baddr = bsh + offset;
  433 
  434         while (count--) {
  435                 wr32(baddr, *addr++);
  436                 baddr += 4;
  437         }
  438 }
  439 
  440 /*
  441  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
  442  * by tag/handle/offset `count' times.
  443  */
  444 void
  445 octopci_bs_sm_1(void *t, bus_space_handle_t bsh,
  446     bus_size_t offset, uint8_t value, size_t count)
  447 {
  448         bus_addr_t addr = bsh + offset;
  449 
  450         while (count--)
  451                 wr8(addr, value);
  452 }
  453 
  454 void
  455 octopci_bs_sm_2(void *t, bus_space_handle_t bsh,
  456     bus_size_t offset, uint16_t value, size_t count)
  457 {
  458         bus_addr_t addr = bsh + offset;
  459 
  460         while (count--)
  461                 wr16(addr, value);
  462 }
  463 
  464 void
  465 octopci_bs_sm_4(void *t, bus_space_handle_t bsh,
  466     bus_size_t offset, uint32_t value, size_t count)
  467 {
  468         bus_addr_t addr = bsh + offset;
  469 
  470         while (count--)
  471                 wr32(addr, value);
  472 }
  473 
  474 /*
  475  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
  476  * by tag/handle starting at `offset'.
  477  */
  478 void
  479 octopci_bs_sr_1(void *t, bus_space_handle_t bsh,
  480     bus_size_t offset, uint8_t value, size_t count)
  481 {
  482         bus_addr_t addr = bsh + offset;
  483 
  484         for (; count != 0; count--, addr++)
  485                 wr8(addr, value);
  486 }
  487 
  488 void
  489 octopci_bs_sr_2(void *t, bus_space_handle_t bsh,
  490                        bus_size_t offset, uint16_t value, size_t count)
  491 {
  492         bus_addr_t addr = bsh + offset;
  493 
  494         for (; count != 0; count--, addr += 2)
  495                 wr16(addr, value);
  496 }
  497 
  498 void
  499 octopci_bs_sr_4(void *t, bus_space_handle_t bsh,
  500     bus_size_t offset, uint32_t value, size_t count)
  501 {
  502         bus_addr_t addr = bsh + offset;
  503 
  504         for (; count != 0; count--, addr += 4)
  505                 wr32(addr, value);
  506 }
  507 
  508 /*
  509  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
  510  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
  511  */
  512 void
  513 octopci_bs_c_1(void *t, bus_space_handle_t bsh1,
  514     bus_size_t off1, bus_space_handle_t bsh2,
  515     bus_size_t off2, size_t count)
  516 {
  517         bus_addr_t addr1 = bsh1 + off1;
  518         bus_addr_t addr2 = bsh2 + off2;
  519 
  520         if (addr1 >= addr2) {
  521                 /* src after dest: copy forward */
  522                 for (; count != 0; count--, addr1++, addr2++)
  523                         wr8(addr2, rd8(addr1));
  524         } else {
  525                 /* dest after src: copy backwards */
  526                 for (addr1 += (count - 1), addr2 += (count - 1);
  527                     count != 0; count--, addr1--, addr2--)
  528                         wr8(addr2, rd8(addr1));
  529         }
  530 }
  531 
  532 void
  533 octopci_bs_c_2(void *t, bus_space_handle_t bsh1,
  534     bus_size_t off1, bus_space_handle_t bsh2,
  535     bus_size_t off2, size_t count)
  536 {
  537         bus_addr_t addr1 = bsh1 + off1;
  538         bus_addr_t addr2 = bsh2 + off2;
  539 
  540         if (addr1 >= addr2) {
  541                 /* src after dest: copy forward */
  542                 for (; count != 0; count--, addr1 += 2, addr2 += 2)
  543                         wr16(addr2, rd16(addr1));
  544         } else {
  545                 /* dest after src: copy backwards */
  546                 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
  547                     count != 0; count--, addr1 -= 2, addr2 -= 2)
  548                         wr16(addr2, rd16(addr1));
  549         }
  550 }
  551 
  552 void
  553 octopci_bs_c_4(void *t, bus_space_handle_t bsh1,
  554     bus_size_t off1, bus_space_handle_t bsh2,
  555     bus_size_t off2, size_t count)
  556 {
  557         bus_addr_t addr1 = bsh1 + off1;
  558         bus_addr_t addr2 = bsh2 + off2;
  559 
  560         if (addr1 >= addr2) {
  561                 /* src after dest: copy forward */
  562                 for (; count != 0; count--, addr1 += 4, addr2 += 4)
  563                         wr32(addr2, rd32(addr1));
  564         } else {
  565                 /* dest after src: copy backwards */
  566                 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
  567                     count != 0; count--, addr1 -= 4, addr2 -= 4)
  568                         wr32(addr2, rd32(addr1));
  569         }
  570 }
  571 
  572 void
  573 octopci_bs_barrier(void *t __unused, 
  574                 bus_space_handle_t bsh __unused,
  575                 bus_size_t offset __unused, bus_size_t len __unused, 
  576                 int flags)
  577 {
  578 #if 0
  579         if (flags & BUS_SPACE_BARRIER_WRITE)
  580                 mips_dcache_wbinv_all();
  581 #endif
  582 }

Cache object: bb10557fab75828fb69e5322b17c0dda


[ 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.