| 1 | \ ========== Copyright Header Begin ========================================== |
| 2 | \ |
| 3 | \ Hypervisor Software File: bge-map.fth |
| 4 | \ |
| 5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 6 | \ |
| 7 | \ - Do no alter or remove copyright notices |
| 8 | \ |
| 9 | \ - Redistribution and use of this software in source and binary forms, with |
| 10 | \ or without modification, are permitted provided that the following |
| 11 | \ conditions are met: |
| 12 | \ |
| 13 | \ - Redistribution of source code must retain the above copyright notice, |
| 14 | \ this list of conditions and the following disclaimer. |
| 15 | \ |
| 16 | \ - Redistribution in binary form must reproduce the above copyright notice, |
| 17 | \ this list of conditions and the following disclaimer in the |
| 18 | \ documentation and/or other materials provided with the distribution. |
| 19 | \ |
| 20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors |
| 21 | \ may be used to endorse or promote products derived from this software |
| 22 | \ without specific prior written permission. |
| 23 | \ |
| 24 | \ This software is provided "AS IS," without a warranty of any kind. |
| 25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, |
| 26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A |
| 27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN |
| 28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR |
| 29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR |
| 30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN |
| 31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR |
| 32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE |
| 33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, |
| 34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF |
| 35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
| 36 | \ |
| 37 | \ You acknowledge that this software is not designed, licensed or |
| 38 | \ intended for use in the design, construction, operation or maintenance of |
| 39 | \ any nuclear facility. |
| 40 | \ |
| 41 | \ ========== Copyright Header End ============================================ |
| 42 | id: @(#)bge-map.fth 1.1 02/09/06 |
| 43 | purpose: Map routines |
| 44 | copyright: Copyright 2002 Sun Microsystems, Inc. All Rights Reserved |
| 45 | copyright: Use is subject to license terms. |
| 46 | |
| 47 | headers |
| 48 | |
| 49 | : map-in ( phys.lo .. phys.hi size -- vaddr ) " map-in" $call-parent ; |
| 50 | |
| 51 | : map-out ( vaddr size -- ) " map-out" $call-parent ; |
| 52 | |
| 53 | : dma-alloc ( size -- vaddr ) " dma-alloc" $call-parent ; |
| 54 | : dma-free ( vaddr size -- ) " dma-free" $call-parent ; |
| 55 | |
| 56 | : dma-map-in ( vaddr n cache? -- devaddr ) " dma-map-in" $call-parent ; |
| 57 | : dma-map-out ( vaddr devaddr n -- ) " dma-map-out" $call-parent ; |
| 58 | |
| 59 | : dma-sync ( virt-adr dev-adr size -- ) |
| 60 | " dma-sync" ['] $call-parent catch if |
| 61 | 3drop 2drop |
| 62 | then |
| 63 | ; |
| 64 | |
| 65 | \ The BGE is essentially a Big Endian PCI device. Depending on the value of |
| 66 | \ PCI configuration register h# 68, it may try to make itself look like a |
| 67 | \ Little Endian Device. There are some quirks though. When fetching/storing |
| 68 | \ SOME registers via 32 bit access it gives unexpected data. Ex. If you try |
| 69 | \ to access the mailbox register at address 200 it will give you the data from |
| 70 | \ address 204. If you access 204 it will give you the data from address 200. |
| 71 | \ However, this is not the case with all registers. As far as I can tell, all |
| 72 | \ 32 bit registers give you the correct data. The mailbox registers are |
| 73 | \ special because they used to be 64 bit registers on the 5701, but as of the |
| 74 | \ 5703 they are 32 bit. |
| 75 | \ Rather than worry about doing xor arithmetic on register address, we will |
| 76 | \ use the same solution as Solaris. Namely, let the device be its native Big |
| 77 | \ Endian, and update the local r() words appropriately. |
| 78 | |
| 79 | : my-rl@ ( adr -- l ) rl@ lbflip ; |
| 80 | : my-rl! ( l adr -- ) >r lbflip r> rl! ; |
| 81 | |
| 82 | \ FCODE rx operators are broken, so use rl instead |
| 83 | : my-rx@ ( adr -- x ) dup 4 + my-rl@ swap my-rl@ lxjoin ; |
| 84 | : my-rx! ( x adr -- ) >r xlsplit r@ my-rl! r> 4 + my-rl! ; |
| 85 | |
| 86 | : local-w! ( data offset -- ) w! ; |
| 87 | : local-w@ ( offset -- data ) w@ ; |
| 88 | : local! ( data offset -- ) l! ; |
| 89 | : local@ ( offset -- data ) l@ ; |
| 90 | : local-x! ( data offset -- ) x! ; |
| 91 | : local-x@ ( offset -- data ) x@ ; |
| 92 | |
| 93 | : my-bset ( bits offset -- ) tuck my-b@ or swap my-b! ; |
| 94 | : my-bclear ( bits offset -- ) dup my-b@ rot invert and swap my-b! ; |
| 95 | : my-wset ( bits offset -- ) tuck my-w@ or swap my-w! ; |
| 96 | : my-wclear ( bits offset -- ) dup my-w@ rot invert and swap my-w! ; |
| 97 | : my-lset ( bits offset -- ) tuck my-l@ or swap my-l! ; |
| 98 | : my-lclear ( bits offset -- ) dup my-l@ rot invert and swap my-l! ; |
| 99 | |
| 100 | : breg@ ( offset -- data ) breg-base + my-rl@ ; |
| 101 | : breg! ( data offset -- ) breg-base + my-rl! ; |
| 102 | |
| 103 | : breg-x! ( data offset -- ) breg-base + my-rx! ; |
| 104 | : breg-x@ ( offset -- data ) breg-base + my-rx@ ; |
| 105 | |
| 106 | : breg-bset ( data offset -- ) dup breg@ rot or swap breg! ; |
| 107 | : breg-bclear ( data offset -- ) dup breg@ rot invert and swap breg! ; |
| 108 | |
| 109 | : set-nic-reg ( adr -- adr' ) \ Nic memory is divided up into 32K chunks |
| 110 | h# 8000 /mod h# 8000 * h# 7c my-l! |
| 111 | ; |
| 112 | |
| 113 | : nicmem! ( data offset -- ) set-nic-reg bmem-base + my-rl! ; |
| 114 | : nicmem@ ( offset -- data ) set-nic-reg bmem-base + my-rl@ ; |
| 115 | |
| 116 | : nicmem-x! ( data offset -- ) set-nic-reg bmem-base + my-rx! ; |
| 117 | : nicmem-x@ ( data -- offset ) set-nic-reg bmem-base + my-rx@ ; |
| 118 | |
| 119 | \ Conversion between cpu dma address and io dma address. |
| 120 | : cpu>io-adr ( cpu-adr -- io-adr ) cpu-dma-base - io-dma-base + ; |
| 121 | : io>cpu-adr ( io-adr -- cpu-adr ) io-dma-base - cpu-dma-base + ; |
| 122 | |
| 123 | : map-buffers ( -- ) |
| 124 | /dma-blk dma-alloc to cpu-dma-base |
| 125 | cpu-dma-base /dma-blk false dma-map-in to io-dma-base |
| 126 | ; |
| 127 | |
| 128 | : unmap-buffers ( -- ) |
| 129 | cpu-dma-base io-dma-base /dma-blk dma-map-out |
| 130 | cpu-dma-base /dma-blk dma-free |
| 131 | 0 to cpu-dma-base 0 to io-dma-base |
| 132 | ; |
| 133 | |
| 134 | : map-regs ( -- ) |
| 135 | my-address my-space h# 300.0010 or h# 10.000 map-in |
| 136 | dup to breg-base |
| 137 | h# 8000 + to bmem-base |
| 138 | ; |
| 139 | |
| 140 | : unmap-regs ( -- ) |
| 141 | breg-base h# 10000 map-out |
| 142 | 0 to breg-base 0 to bmem-base |
| 143 | ; |
| 144 | |
| 145 | : map-resources ( -- ) |
| 146 | breg-base 0= if map-regs map-buffers then |
| 147 | ; |
| 148 | |
| 149 | : unmap-resources ( -- ) |
| 150 | breg-base if unmap-buffers unmap-regs then |
| 151 | ; |
| 152 | |