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 | |
| 59 | #if defined(CONFIG_MSM_IOMMU) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 60 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 61 | extern struct iommu_domain *msm_get_iommu_domain(int domain_num); |
| 62 | |
| 63 | extern unsigned long msm_allocate_iova_address(unsigned int iommu_domain, |
| 64 | unsigned int partition_no, |
| 65 | unsigned long size, |
| 66 | unsigned long align); |
| 67 | |
| 68 | extern void msm_free_iova_address(unsigned long iova, |
| 69 | unsigned int iommu_domain, |
| 70 | unsigned int partition_no, |
| 71 | unsigned long size); |
| 72 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 73 | extern int msm_use_iommu(void); |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 74 | |
| 75 | extern int msm_iommu_map_extra(struct iommu_domain *domain, |
| 76 | unsigned long start_iova, |
| 77 | unsigned long size, |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame^] | 78 | unsigned long page_size, |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 79 | int cached); |
| 80 | |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame^] | 81 | extern void msm_iommu_unmap_extra(struct iommu_domain *domain, |
| 82 | unsigned long start_iova, |
| 83 | unsigned long size, |
| 84 | unsigned long page_size); |
| 85 | |
Laura Abbott | d027fdb | 2012-04-17 16:22:24 -0700 | [diff] [blame] | 86 | extern int msm_iommu_map_contig_buffer(unsigned long phys, |
| 87 | unsigned int domain_no, |
| 88 | unsigned int partition_no, |
| 89 | unsigned long size, |
| 90 | unsigned long align, |
| 91 | unsigned long cached, |
| 92 | unsigned long *iova_val); |
| 93 | |
| 94 | |
| 95 | extern void msm_iommu_unmap_contig_buffer(unsigned long iova, |
| 96 | unsigned int domain_no, |
| 97 | unsigned int partition_no, |
| 98 | unsigned long size); |
| 99 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 100 | #else |
| 101 | static inline struct iommu_domain |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 102 | *msm_get_iommu_domain(int subsys_id) { return NULL; } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 103 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 104 | |
| 105 | |
| 106 | static inline unsigned long msm_allocate_iova_address(unsigned int iommu_domain, |
| 107 | unsigned int partition_no, |
| 108 | unsigned long size, |
| 109 | unsigned long align) { return 0; } |
| 110 | |
| 111 | static inline void msm_free_iova_address(unsigned long iova, |
| 112 | unsigned int iommu_domain, |
| 113 | unsigned int partition_no, |
| 114 | unsigned long size) { return; } |
| 115 | |
Laura Abbott | 9f4a8e6 | 2011-08-29 19:08:07 -0700 | [diff] [blame] | 116 | static inline int msm_use_iommu(void) |
| 117 | { |
| 118 | return 0; |
| 119 | } |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 120 | |
| 121 | static inline int msm_iommu_map_extra(struct iommu_domain *domain, |
| 122 | unsigned long start_iova, |
| 123 | unsigned long size, |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame^] | 124 | unsigned long page_size, |
Laura Abbott | e956cce | 2011-10-25 13:33:20 -0700 | [diff] [blame] | 125 | int cached) |
| 126 | { |
| 127 | return -ENODEV; |
| 128 | } |
Laura Abbott | d027fdb | 2012-04-17 16:22:24 -0700 | [diff] [blame] | 129 | |
Olav Haugan | 8726caf | 2012-05-10 15:11:35 -0700 | [diff] [blame^] | 130 | static inline void msm_iommu_unmap_extra(struct iommu_domain *domain, |
| 131 | unsigned long start_iova, |
| 132 | unsigned long size, |
| 133 | unsigned long page_size) |
| 134 | { |
| 135 | } |
Laura Abbott | d027fdb | 2012-04-17 16:22:24 -0700 | [diff] [blame] | 136 | |
| 137 | static inline int msm_iommu_map_contig_buffer(unsigned long phys, |
| 138 | unsigned int domain_no, |
| 139 | unsigned int partition_no, |
| 140 | unsigned long size, |
| 141 | unsigned long align, |
| 142 | unsigned long cached, |
| 143 | unsigned long *iova_val) |
| 144 | { |
| 145 | *iova_val = phys; |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static inline void msm_iommu_unmap_contig_buffer(unsigned long iova, |
| 150 | unsigned int domain_no, |
| 151 | unsigned int partition_no, |
| 152 | unsigned long size) |
| 153 | { |
| 154 | return; |
| 155 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 156 | #endif |
| 157 | |
| 158 | #endif |