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