Olav Haugan | ab77b1b | 2012-02-28 09:19:22 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef _ARCH_IOMMU_DOMAINS_H |
| 14 | #define _ARCH_IOMMU_DOMAINS_H |
| 15 | |
Laura Abbott | 0577d7b | 2012-04-17 11:14:30 -0700 | [diff] [blame] | 16 | #include <linux/memory_alloc.h> |
| 17 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 18 | enum { |
Olav Haugan | ab77b1b | 2012-02-28 09:19:22 -0800 | [diff] [blame] | 19 | VIDEO_DOMAIN, |
Olav Haugan | 2d19103 | 2012-02-28 09:46:31 -0800 | [diff] [blame] | 20 | CAMERA_DOMAIN, |
Olav Haugan | ef95ae3 | 2012-05-15 09:50:30 -0700 | [diff] [blame] | 21 | DISPLAY_READ_DOMAIN, |
| 22 | DISPLAY_WRITE_DOMAIN, |
| 23 | ROTATOR_SRC_DOMAIN, |
| 24 | ROTATOR_DST_DOMAIN, |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 25 | MAX_DOMAINS |
| 26 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 28 | enum { |
| 29 | VIDEO_FIRMWARE_POOL, |
Olav Haugan | ee36536 | 2012-02-16 09:31:37 -0800 | [diff] [blame] | 30 | VIDEO_MAIN_POOL, |
Olav Haugan | ee36536 | 2012-02-16 09:31:37 -0800 | [diff] [blame] | 31 | GEN_POOL, |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
Laura Abbott | 0577d7b | 2012-04-17 11:14:30 -0700 | [diff] [blame] | 34 | struct msm_iommu_domain_name { |
| 35 | char *name; |
| 36 | int domain; |
| 37 | }; |
| 38 | |
| 39 | struct msm_iommu_domain { |
| 40 | /* iommu domain to map in */ |
| 41 | struct iommu_domain *domain; |
| 42 | /* total number of allocations from this domain */ |
| 43 | atomic_t allocation_cnt; |
| 44 | /* number of iova pools */ |
| 45 | int npools; |
| 46 | /* |
| 47 | * array of gen_pools for allocating iovas. |
| 48 | * behavior is undefined if these overlap |
| 49 | */ |
| 50 | struct mem_pool *iova_pools; |
| 51 | }; |
| 52 | |
| 53 | struct iommu_domains_pdata { |
| 54 | struct msm_iommu_domain *domains; |
| 55 | int ndomains; |
| 56 | struct msm_iommu_domain_name *domain_names; |
| 57 | int nnames; |
| 58 | unsigned int domain_alloc_flags; |
| 59 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 60 | |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 61 | |
| 62 | struct msm_iova_partition { |
| 63 | unsigned long start; |
| 64 | unsigned long size; |
| 65 | }; |
| 66 | |
| 67 | struct msm_iova_layout { |
| 68 | struct msm_iova_partition *partitions; |
| 69 | int npartitions; |
| 70 | const char *client_name; |
| 71 | unsigned int domain_flags; |
| 72 | }; |
| 73 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | #if defined(CONFIG_MSM_IOMMU) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 76 | extern struct iommu_domain *msm_get_iommu_domain(int domain_num); |
| 77 | |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 78 | extern int msm_allocate_iova_address(unsigned int iommu_domain, |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 79 | unsigned int partition_no, |
| 80 | unsigned long size, |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 81 | unsigned long align, |
| 82 | unsigned long *iova); |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 83 | |
| 84 | extern void msm_free_iova_address(unsigned long iova, |
| 85 | unsigned int iommu_domain, |
| 86 | unsigned int partition_no, |
| 87 | unsigned long size); |
| 88 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 89 | extern int msm_use_iommu(void); |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 90 | |
| 91 | extern int msm_iommu_map_extra(struct iommu_domain *domain, |
| 92 | unsigned long start_iova, |
| 93 | unsigned long size, |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame] | 94 | unsigned long page_size, |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 95 | int cached); |
| 96 | |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame] | 97 | extern void msm_iommu_unmap_extra(struct iommu_domain *domain, |
| 98 | unsigned long start_iova, |
| 99 | unsigned long size, |
| 100 | unsigned long page_size); |
| 101 | |
Laura Abbott | d027fdb | 2012-04-17 16:22:24 -0700 | [diff] [blame] | 102 | extern int msm_iommu_map_contig_buffer(unsigned long phys, |
| 103 | unsigned int domain_no, |
| 104 | unsigned int partition_no, |
| 105 | unsigned long size, |
| 106 | unsigned long align, |
| 107 | unsigned long cached, |
| 108 | unsigned long *iova_val); |
| 109 | |
| 110 | |
| 111 | extern void msm_iommu_unmap_contig_buffer(unsigned long iova, |
| 112 | unsigned int domain_no, |
| 113 | unsigned int partition_no, |
| 114 | unsigned long size); |
| 115 | |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 116 | extern int msm_register_domain(struct msm_iova_layout *layout); |
| 117 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 118 | #else |
| 119 | static inline struct iommu_domain |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 120 | *msm_get_iommu_domain(int subsys_id) { return NULL; } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 121 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 122 | |
| 123 | |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 124 | static inline int msm_allocate_iova_address(unsigned int iommu_domain, |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 125 | unsigned int partition_no, |
| 126 | unsigned long size, |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 127 | unsigned long align, |
| 128 | unsigned long *iova) { return -ENOMEM; } |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 129 | |
| 130 | static inline void msm_free_iova_address(unsigned long iova, |
| 131 | unsigned int iommu_domain, |
| 132 | unsigned int partition_no, |
| 133 | unsigned long size) { return; } |
| 134 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 135 | static inline int msm_use_iommu(void) |
| 136 | { |
| 137 | return 0; |
| 138 | } |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 139 | |
| 140 | static inline int msm_iommu_map_extra(struct iommu_domain *domain, |
| 141 | unsigned long start_iova, |
| 142 | unsigned long size, |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame] | 143 | unsigned long page_size, |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 144 | int cached) |
| 145 | { |
| 146 | return -ENODEV; |
| 147 | } |
Laura Abbott | d027fdb | 2012-04-17 16:22:24 -0700 | [diff] [blame] | 148 | |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame] | 149 | static inline void msm_iommu_unmap_extra(struct iommu_domain *domain, |
| 150 | unsigned long start_iova, |
| 151 | unsigned long size, |
| 152 | unsigned long page_size) |
| 153 | { |
| 154 | } |
Laura Abbott | d027fdb | 2012-04-17 16:22:24 -0700 | [diff] [blame] | 155 | |
| 156 | static inline int msm_iommu_map_contig_buffer(unsigned long phys, |
| 157 | unsigned int domain_no, |
| 158 | unsigned int partition_no, |
| 159 | unsigned long size, |
| 160 | unsigned long align, |
| 161 | unsigned long cached, |
| 162 | unsigned long *iova_val) |
| 163 | { |
| 164 | *iova_val = phys; |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | static inline void msm_iommu_unmap_contig_buffer(unsigned long iova, |
| 169 | unsigned int domain_no, |
| 170 | unsigned int partition_no, |
| 171 | unsigned long size) |
| 172 | { |
| 173 | return; |
| 174 | } |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 175 | |
| 176 | static inline int msm_register_domain(struct msm_iova_layout *layout) |
| 177 | { |
| 178 | return -ENODEV; |
| 179 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 180 | #endif |
| 181 | |
| 182 | #endif |