armv7_space.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* $OpenBSD: armv7_space.c,v 1.6 2014/11/16 12:30:56 deraadt Exp $ */
  2. /*
  3. * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
  4. * All rights reserved.
  5. *
  6. * Written by Jason R. Thorpe for Wasabi Systems, Inc.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. All advertising materials mentioning features or use of this software
  17. * must display the following acknowledgement:
  18. * This product includes software developed for the NetBSD Project by
  19. * Wasabi Systems, Inc.
  20. * 4. The name of Wasabi Systems, Inc. may not be used to endorse
  21. * or promote products derived from this software without specific prior
  22. * written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  26. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
  28. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. /*
  37. * Copyright (c) 1997 Mark Brinicombe.
  38. * Copyright (c) 1997 Causality Limited.
  39. * All rights reserved.
  40. *
  41. * This code is derived from software contributed to The NetBSD Foundation
  42. * by Ichiro FUKUHARA.
  43. *
  44. * Redistribution and use in source and binary forms, with or without
  45. * modification, are permitted provided that the following conditions
  46. * are met:
  47. * 1. Redistributions of source code must retain the above copyright
  48. * notice, this list of conditions and the following disclaimer.
  49. * 2. Redistributions in binary form must reproduce the above copyright
  50. * notice, this list of conditions and the following disclaimer in the
  51. * documentation and/or other materials provided with the distribution.
  52. * 3. All advertising materials mentioning features or use of this software
  53. * must display the following acknowledgement:
  54. * This product includes software developed by Mark Brinicombe.
  55. * 4. The name of the company nor the name of the author may be used to
  56. * endorse or promote products derived from this software without specific
  57. * prior written permission.
  58. *
  59. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  60. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  61. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  62. * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  63. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  64. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  66. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  69. * SUCH DAMAGE.
  70. */
  71. /*
  72. * bus_space functions for Intel PXA2[51]0 application processor.
  73. * Derived from i80321_space.c.
  74. */
  75. #include <sys/param.h>
  76. #include <sys/systm.h>
  77. #include <uvm/uvm_extern.h>
  78. #include <machine/bus.h>
  79. /* Prototypes for all the bus_space structure functions */
  80. bs_protos(armv7);
  81. bs_protos(generic);
  82. bs_protos(bs_notimpl);
  83. struct bus_space armv7_bs_tag = {
  84. /* cookie */
  85. (void *) 0,
  86. /* mapping/unmapping */
  87. armv7_bs_map,
  88. armv7_bs_unmap,
  89. armv7_bs_subregion,
  90. /* allocation/deallocation */
  91. armv7_bs_alloc, /* not implemented */
  92. armv7_bs_free, /* not implemented */
  93. /* get kernel virtual address */
  94. armv7_bs_vaddr,
  95. /* mmap */
  96. bs_notimpl_bs_mmap,
  97. /* barrier */
  98. armv7_bs_barrier,
  99. /* read (single) */
  100. armv7_bs_r_1,
  101. armv7_bs_r_2,
  102. armv7_bs_r_4,
  103. bs_notimpl_bs_r_8,
  104. /* read multiple */
  105. armv7_bs_rm_1,
  106. armv7_bs_rm_2,
  107. armv7_bs_rm_4,
  108. bs_notimpl_bs_rm_8,
  109. /* read region */
  110. armv7_bs_rr_1,
  111. armv7_bs_rr_2,
  112. armv7_bs_rr_4,
  113. bs_notimpl_bs_rr_8,
  114. /* write (single) */
  115. armv7_bs_w_1,
  116. armv7_bs_w_2,
  117. armv7_bs_w_4,
  118. bs_notimpl_bs_w_8,
  119. /* write multiple */
  120. armv7_bs_wm_1,
  121. armv7_bs_wm_2,
  122. armv7_bs_wm_4,
  123. bs_notimpl_bs_wm_8,
  124. /* write region */
  125. armv7_bs_wr_1,
  126. armv7_bs_wr_2,
  127. armv7_bs_wr_4,
  128. bs_notimpl_bs_wr_8,
  129. /* set multiple */
  130. bs_notimpl_bs_sm_1,
  131. bs_notimpl_bs_sm_2,
  132. bs_notimpl_bs_sm_4,
  133. bs_notimpl_bs_sm_8,
  134. /* set region */
  135. armv7_bs_sr_1,
  136. armv7_bs_sr_2,
  137. armv7_bs_sr_4,
  138. bs_notimpl_bs_sr_8,
  139. /* copy */
  140. bs_notimpl_bs_c_1,
  141. armv7_bs_c_2,
  142. bs_notimpl_bs_c_4,
  143. bs_notimpl_bs_c_8,
  144. };
  145. int
  146. armv7_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
  147. int flag, bus_space_handle_t *bshp)
  148. {
  149. u_long startpa, endpa, pa;
  150. vaddr_t va;
  151. pt_entry_t *pte;
  152. if ((u_long)bpa > (u_long)KERNEL_BASE) {
  153. /* Some IO registers (ex. UART ports for console)
  154. are mapped to fixed address by board specific
  155. routine. */
  156. *bshp = bpa;
  157. return(0);
  158. }
  159. startpa = trunc_page(bpa);
  160. endpa = round_page(bpa + size);
  161. /* XXX use extent manager to check duplicate mapping */
  162. va = uvm_km_valloc(kernel_map, endpa - startpa);
  163. if (! va)
  164. return(ENOMEM);
  165. *bshp = (bus_space_handle_t)(va + (bpa - startpa));
  166. for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
  167. pmap_kenter_pa(va, pa, PROT_READ | PROT_WRITE);
  168. if ((flag & BUS_SPACE_MAP_CACHEABLE) == 0) {
  169. pte = vtopte(va);
  170. *pte &= ~L2_S_CACHE_MASK;
  171. *pte |= L2_B;
  172. PTE_SYNC(pte);
  173. /* XXX: pmap_kenter_pa() also does PTE_SYNC(). a bit of
  174. * waste.
  175. */
  176. }
  177. }
  178. pmap_update(pmap_kernel());
  179. return(0);
  180. }
  181. void
  182. armv7_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
  183. {
  184. vaddr_t va, endva;
  185. if (bsh > (u_long)KERNEL_BASE)
  186. return;
  187. va = trunc_page((vaddr_t)bsh);
  188. endva = round_page((vaddr_t)bsh + size);
  189. pmap_kremove(va, endva - va);
  190. pmap_update(pmap_kernel());
  191. uvm_km_free(kernel_map, bsh, size);
  192. }
  193. int
  194. armv7_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
  195. bus_size_t size, bus_space_handle_t *nbshp)
  196. {
  197. *nbshp = bsh + offset;
  198. return (0);
  199. }
  200. void
  201. armv7_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
  202. bus_size_t len, int flags)
  203. {
  204. cpu_drain_writebuf();
  205. }
  206. void *
  207. armv7_bs_vaddr(void *t, bus_space_handle_t bsh)
  208. {
  209. return ((void *)bsh);
  210. }
  211. int
  212. armv7_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
  213. bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
  214. bus_addr_t *bpap, bus_space_handle_t *bshp)
  215. {
  216. panic("armv7_io_bs_alloc(): not implemented");
  217. }
  218. void
  219. armv7_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
  220. {
  221. panic("armv7_io_bs_free(): not implemented");
  222. }