Mitchel Humpherys | af3b522 | 2013-01-15 15:38:52 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. 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 | 6a6ca55 | 2012-08-30 11:26:31 -0700 | [diff] [blame] | 18 | #define MSM_IOMMU_DOMAIN_SECURE 0x1 |
| 19 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 20 | enum { |
Olav Haugan | ab77b1b | 2012-02-28 09:19:22 -0800 | [diff] [blame] | 21 | VIDEO_DOMAIN, |
Olav Haugan | 2d19103 | 2012-02-28 09:46:31 -0800 | [diff] [blame] | 22 | CAMERA_DOMAIN, |
Olav Haugan | ef95ae3 | 2012-05-15 09:50:30 -0700 | [diff] [blame] | 23 | DISPLAY_READ_DOMAIN, |
| 24 | DISPLAY_WRITE_DOMAIN, |
| 25 | ROTATOR_SRC_DOMAIN, |
| 26 | ROTATOR_DST_DOMAIN, |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 27 | MAX_DOMAINS |
| 28 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 29 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 30 | enum { |
| 31 | VIDEO_FIRMWARE_POOL, |
Olav Haugan | ee36536 | 2012-02-16 09:31:37 -0800 | [diff] [blame] | 32 | VIDEO_MAIN_POOL, |
Olav Haugan | ee36536 | 2012-02-16 09:31:37 -0800 | [diff] [blame] | 33 | GEN_POOL, |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Laura Abbott | 0577d7b | 2012-04-17 11:14:30 -0700 | [diff] [blame] | 36 | struct msm_iommu_domain_name { |
| 37 | char *name; |
| 38 | int domain; |
| 39 | }; |
| 40 | |
| 41 | struct msm_iommu_domain { |
| 42 | /* iommu domain to map in */ |
| 43 | struct iommu_domain *domain; |
| 44 | /* total number of allocations from this domain */ |
| 45 | atomic_t allocation_cnt; |
| 46 | /* number of iova pools */ |
| 47 | int npools; |
| 48 | /* |
| 49 | * array of gen_pools for allocating iovas. |
| 50 | * behavior is undefined if these overlap |
| 51 | */ |
| 52 | struct mem_pool *iova_pools; |
| 53 | }; |
| 54 | |
| 55 | struct iommu_domains_pdata { |
| 56 | struct msm_iommu_domain *domains; |
| 57 | int ndomains; |
| 58 | struct msm_iommu_domain_name *domain_names; |
| 59 | int nnames; |
| 60 | unsigned int domain_alloc_flags; |
| 61 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 62 | |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 63 | |
| 64 | struct msm_iova_partition { |
| 65 | unsigned long start; |
| 66 | unsigned long size; |
| 67 | }; |
| 68 | |
| 69 | struct msm_iova_layout { |
| 70 | struct msm_iova_partition *partitions; |
| 71 | int npartitions; |
| 72 | const char *client_name; |
| 73 | unsigned int domain_flags; |
Laura Abbott | 6a6ca55 | 2012-08-30 11:26:31 -0700 | [diff] [blame] | 74 | unsigned int is_secure; |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 77 | #if defined(CONFIG_MSM_IOMMU) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | |
Olav Haugan | a9820ce | 2013-03-22 14:50:28 -0700 | [diff] [blame] | 79 | extern void msm_iommu_set_client_name(struct iommu_domain *domain, |
| 80 | char const *name); |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 81 | extern struct iommu_domain *msm_get_iommu_domain(int domain_num); |
Olav Haugan | 35deadc | 2012-12-10 18:28:27 -0800 | [diff] [blame] | 82 | extern int msm_find_domain_no(const struct iommu_domain *domain); |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 83 | |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 84 | extern int msm_allocate_iova_address(unsigned int iommu_domain, |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 85 | unsigned int partition_no, |
| 86 | unsigned long size, |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 87 | unsigned long align, |
| 88 | unsigned long *iova); |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 89 | |
| 90 | extern void msm_free_iova_address(unsigned long iova, |
| 91 | unsigned int iommu_domain, |
| 92 | unsigned int partition_no, |
| 93 | unsigned long size); |
| 94 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 95 | extern int msm_use_iommu(void); |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 96 | |
| 97 | extern int msm_iommu_map_extra(struct iommu_domain *domain, |
| 98 | unsigned long start_iova, |
Laura Abbott | 3cfa2e6 | 2013-03-13 17:48:26 -0700 | [diff] [blame] | 99 | phys_addr_t phys_addr, |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 100 | unsigned long size, |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame] | 101 | unsigned long page_size, |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 102 | int cached); |
| 103 | |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame] | 104 | extern void msm_iommu_unmap_extra(struct iommu_domain *domain, |
| 105 | unsigned long start_iova, |
| 106 | unsigned long size, |
| 107 | unsigned long page_size); |
| 108 | |
Laura Abbott | 3cfa2e6 | 2013-03-13 17:48:26 -0700 | [diff] [blame] | 109 | extern int msm_iommu_map_contig_buffer(phys_addr_t phys, |
Laura Abbott | d027fdb | 2012-04-17 16:22:24 -0700 | [diff] [blame] | 110 | unsigned int domain_no, |
| 111 | unsigned int partition_no, |
| 112 | unsigned long size, |
| 113 | unsigned long align, |
| 114 | unsigned long cached, |
| 115 | unsigned long *iova_val); |
| 116 | |
| 117 | |
| 118 | extern void msm_iommu_unmap_contig_buffer(unsigned long iova, |
| 119 | unsigned int domain_no, |
| 120 | unsigned int partition_no, |
| 121 | unsigned long size); |
| 122 | |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 123 | extern int msm_register_domain(struct msm_iova_layout *layout); |
| 124 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 125 | #else |
Olav Haugan | a9820ce | 2013-03-22 14:50:28 -0700 | [diff] [blame] | 126 | static inline void msm_iommu_set_client_name(struct iommu_domain *domain, |
| 127 | char const *name) |
| 128 | { |
| 129 | } |
| 130 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 131 | static inline struct iommu_domain |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 132 | *msm_get_iommu_domain(int subsys_id) { return NULL; } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 133 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 134 | |
Olav Haugan | 35deadc | 2012-12-10 18:28:27 -0800 | [diff] [blame] | 135 | static inline int msm_find_domain_no(const struct iommu_domain *domain) |
| 136 | { |
| 137 | return -EINVAL; |
| 138 | } |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 139 | |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 140 | static inline int msm_allocate_iova_address(unsigned int iommu_domain, |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 141 | unsigned int partition_no, |
| 142 | unsigned long size, |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 143 | unsigned long align, |
| 144 | unsigned long *iova) { return -ENOMEM; } |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 145 | |
| 146 | static inline void msm_free_iova_address(unsigned long iova, |
| 147 | unsigned int iommu_domain, |
| 148 | unsigned int partition_no, |
| 149 | unsigned long size) { return; } |
| 150 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 151 | static inline int msm_use_iommu(void) |
| 152 | { |
| 153 | return 0; |
| 154 | } |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 155 | |
| 156 | static inline int msm_iommu_map_extra(struct iommu_domain *domain, |
| 157 | unsigned long start_iova, |
Laura Abbott | 3cfa2e6 | 2013-03-13 17:48:26 -0700 | [diff] [blame] | 158 | phys_addr_t phys_addr, |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 159 | unsigned long size, |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame] | 160 | unsigned long page_size, |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 161 | int cached) |
| 162 | { |
| 163 | return -ENODEV; |
| 164 | } |
Laura Abbott | d027fdb | 2012-04-17 16:22:24 -0700 | [diff] [blame] | 165 | |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame] | 166 | static inline void msm_iommu_unmap_extra(struct iommu_domain *domain, |
| 167 | unsigned long start_iova, |
| 168 | unsigned long size, |
| 169 | unsigned long page_size) |
| 170 | { |
| 171 | } |
Laura Abbott | d027fdb | 2012-04-17 16:22:24 -0700 | [diff] [blame] | 172 | |
Laura Abbott | 3cfa2e6 | 2013-03-13 17:48:26 -0700 | [diff] [blame] | 173 | static inline int msm_iommu_map_contig_buffer(phys_addr_t phys, |
Laura Abbott | d027fdb | 2012-04-17 16:22:24 -0700 | [diff] [blame] | 174 | unsigned int domain_no, |
| 175 | unsigned int partition_no, |
| 176 | unsigned long size, |
| 177 | unsigned long align, |
| 178 | unsigned long cached, |
| 179 | unsigned long *iova_val) |
| 180 | { |
| 181 | *iova_val = phys; |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static inline void msm_iommu_unmap_contig_buffer(unsigned long iova, |
| 186 | unsigned int domain_no, |
| 187 | unsigned int partition_no, |
| 188 | unsigned long size) |
| 189 | { |
| 190 | return; |
| 191 | } |
Laura Abbott | d01221b | 2012-05-16 17:52:49 -0700 | [diff] [blame] | 192 | |
| 193 | static inline int msm_register_domain(struct msm_iova_layout *layout) |
| 194 | { |
| 195 | return -ENODEV; |
| 196 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 197 | #endif |
| 198 | |
| 199 | #endif |