Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 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 __KGSL_IOMMU_H |
| 14 | #define __KGSL_IOMMU_H |
| 15 | |
| 16 | #include <mach/iommu.h> |
| 17 | |
Shubhraprakash Das | 2b8716b | 2012-05-04 16:58:40 -0600 | [diff] [blame] | 18 | /* IOMMU registers and masks */ |
| 19 | #define KGSL_IOMMU_TTBR0 0x10 |
| 20 | #define KGSL_IOMMU_TTBR1 0x14 |
| 21 | #define KGSL_IOMMU_TTBR0_PA_MASK 0x0003FFFF |
| 22 | #define KGSL_IOMMU_TTBR0_PA_SHIFT 14 |
| 23 | #define KGSL_IOMMU_CTX_TLBIALL 0x800 |
| 24 | #define KGSL_IOMMU_CONTEXTIDR 0x8 |
| 25 | #define KGSL_IOMMU_CONTEXTIDR_ASID_MASK 0xFF |
| 26 | #define KGSL_IOMMU_CONTEXTIDR_ASID_SHIFT 0 |
| 27 | #define KGSL_IOMMU_CTX_TLBIASID 0x804 |
| 28 | #define KGSL_IOMMU_CTX_SHIFT 12 |
Shubhraprakash Das | d3f937c | 2012-05-07 12:44:40 -0600 | [diff] [blame] | 29 | |
| 30 | #define KGSL_IOMMU_MAX_ASIDS 256 |
| 31 | #define KGSL_IOMMU_ASID_REUSE 2 |
| 32 | |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 33 | /* |
| 34 | * Max number of iommu units that the gpu core can have |
| 35 | * On APQ8064, KGSL can control a maximum of 2 IOMMU units. |
| 36 | */ |
| 37 | #define KGSL_IOMMU_MAX_UNITS 2 |
| 38 | |
| 39 | /* Max number of iommu contexts per IOMMU unit */ |
| 40 | #define KGSL_IOMMU_MAX_DEVS_PER_UNIT 2 |
| 41 | |
Shubhraprakash Das | d8cbcd1 | 2012-05-07 16:11:32 -0600 | [diff] [blame^] | 42 | /* Macros to read/write IOMMU registers */ |
| 43 | #define KGSL_IOMMU_SET_IOMMU_REG(base_addr, ctx, REG, val) \ |
| 44 | writel_relaxed(val, base_addr + \ |
| 45 | (ctx << KGSL_IOMMU_CTX_SHIFT) + \ |
| 46 | KGSL_IOMMU_##REG) |
| 47 | |
| 48 | #define KGSL_IOMMU_GET_IOMMU_REG(base_addr, ctx, REG) \ |
| 49 | readl_relaxed(base_addr + \ |
| 50 | (ctx << KGSL_IOMMU_CTX_SHIFT) + \ |
| 51 | KGSL_IOMMU_##REG) |
| 52 | |
| 53 | /* Gets the lsb value of pagetable */ |
| 54 | #define KGSL_IOMMMU_PT_LSB(pt_val) \ |
| 55 | (pt_val & ~(KGSL_IOMMU_TTBR0_PA_MASK << \ |
| 56 | KGSL_IOMMU_TTBR0_PA_SHIFT)) |
| 57 | |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 58 | /* |
| 59 | * struct kgsl_iommu_device - Structure holding data about iommu contexts |
| 60 | * @dev: Device pointer to iommu context |
| 61 | * @attached: Indicates whether this iommu context is presently attached to |
| 62 | * a pagetable/domain or not |
| 63 | * @pt_lsb: The LSB of IOMMU_TTBR0 register which is the pagetable |
| 64 | * register |
| 65 | * @ctx_id: This iommu units context id. It can be either 0 or 1 |
| 66 | * @clk_enabled: If set indicates that iommu clocks of this iommu context |
| 67 | * are on, else the clocks are off |
| 68 | */ |
| 69 | struct kgsl_iommu_device { |
| 70 | struct device *dev; |
| 71 | bool attached; |
| 72 | unsigned int pt_lsb; |
| 73 | enum kgsl_iommu_context_id ctx_id; |
| 74 | bool clk_enabled; |
| 75 | }; |
| 76 | |
| 77 | /* |
| 78 | * struct kgsl_iommu_unit - Structure holding data about iommu units. An IOMMU |
| 79 | * units is basically a separte IOMMU h/w block with it's own IOMMU contexts |
| 80 | * @dev: Pointer to array of struct kgsl_iommu_device which has information |
| 81 | * about the IOMMU contexts under this IOMMU unit |
| 82 | * @dev_count: Number of IOMMU contexts that are valid in the previous feild |
| 83 | * @reg_map: Memory descriptor which holds the mapped address of this IOMMU |
| 84 | * units register range |
| 85 | */ |
| 86 | struct kgsl_iommu_unit { |
| 87 | struct kgsl_iommu_device dev[KGSL_IOMMU_MAX_DEVS_PER_UNIT]; |
| 88 | unsigned int dev_count; |
| 89 | struct kgsl_memdesc reg_map; |
| 90 | }; |
| 91 | |
| 92 | /* |
| 93 | * struct kgsl_iommu - Structure holding iommu data for kgsl driver |
| 94 | * @dev: Array of kgsl_iommu_device which contain information about |
| 95 | * iommu contexts owned by graphics cores |
| 96 | * @unit_count: Number of IOMMU units that are available for this |
| 97 | * instance of the IOMMU driver |
| 98 | * @iommu_last_cmd_ts: The timestamp of last command submitted that |
| 99 | * aceeses iommu registers |
| 100 | * @device: Pointer to kgsl device |
| 101 | * @asids: A bit structure indicating which id's are presently used |
| 102 | * @asid: Contains the initial value of IOMMU_CONTEXTIDR when a domain |
| 103 | * is first attached |
Shubhraprakash Das | d3f937c | 2012-05-07 12:44:40 -0600 | [diff] [blame] | 104 | * asid_reuse: Holds the number of times the reuse asid is reused |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 105 | */ |
| 106 | struct kgsl_iommu { |
| 107 | struct kgsl_iommu_unit iommu_units[KGSL_IOMMU_MAX_UNITS]; |
| 108 | unsigned int unit_count; |
| 109 | unsigned int iommu_last_cmd_ts; |
| 110 | struct kgsl_device *device; |
| 111 | unsigned long *asids; |
| 112 | unsigned int asid; |
Shubhraprakash Das | d3f937c | 2012-05-07 12:44:40 -0600 | [diff] [blame] | 113 | unsigned int asid_reuse; |
| 114 | }; |
| 115 | |
| 116 | /* |
| 117 | * struct kgsl_iommu_pt - Iommu pagetable structure private to kgsl driver |
| 118 | * @domain: Pointer to the iommu domain that contains the iommu pagetable |
| 119 | * @iommu: Pointer to iommu structure |
| 120 | * @asid: The asid assigned to this domain |
| 121 | */ |
| 122 | struct kgsl_iommu_pt { |
| 123 | struct iommu_domain *domain; |
| 124 | struct kgsl_iommu *iommu; |
| 125 | unsigned int asid; |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | #endif |