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 | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame^] | 18 | #define KGSL_IOMMU_CTX_OFFSET_V1 0 |
| 19 | #define KGSL_IOMMU_CTX_SHIFT 12 |
Jordan Crouse | 95b6847 | 2012-05-25 10:25:01 -0600 | [diff] [blame] | 20 | |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame^] | 21 | enum kgsl_iommu_reg_map { |
| 22 | KGSL_IOMMU_GLOBAL_BASE = 0, |
| 23 | KGSL_IOMMU_CTX_TTBR0, |
| 24 | KGSL_IOMMU_CTX_TTBR1, |
| 25 | KGSL_IOMMU_CTX_FSR, |
| 26 | KGSL_IOMMU_CTX_TLBIALL, |
| 27 | KGSL_IOMMU_REG_MAX |
| 28 | }; |
| 29 | |
| 30 | struct kgsl_iommu_register_list { |
| 31 | unsigned int reg_offset; |
| 32 | unsigned int reg_mask; |
| 33 | unsigned int reg_shift; |
| 34 | }; |
Shubhraprakash Das | d3f937c | 2012-05-07 12:44:40 -0600 | [diff] [blame] | 35 | |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 36 | /* |
| 37 | * Max number of iommu units that the gpu core can have |
| 38 | * On APQ8064, KGSL can control a maximum of 2 IOMMU units. |
| 39 | */ |
| 40 | #define KGSL_IOMMU_MAX_UNITS 2 |
| 41 | |
| 42 | /* Max number of iommu contexts per IOMMU unit */ |
| 43 | #define KGSL_IOMMU_MAX_DEVS_PER_UNIT 2 |
| 44 | |
Shubhraprakash Das | d8cbcd1 | 2012-05-07 16:11:32 -0600 | [diff] [blame] | 45 | /* Macros to read/write IOMMU registers */ |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame^] | 46 | #define KGSL_IOMMU_SET_CTX_REG(iommu, iommu_unit, ctx, REG, val) \ |
| 47 | writel_relaxed(val, \ |
| 48 | iommu_unit->reg_map.hostptr + \ |
| 49 | iommu->iommu_reg_list[KGSL_IOMMU_CTX_##REG].reg_offset +\ |
| 50 | (ctx << KGSL_IOMMU_CTX_SHIFT) + \ |
| 51 | iommu->ctx_offset) |
Shubhraprakash Das | d8cbcd1 | 2012-05-07 16:11:32 -0600 | [diff] [blame] | 52 | |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame^] | 53 | #define KGSL_IOMMU_GET_CTX_REG(iommu, iommu_unit, ctx, REG) \ |
| 54 | readl_relaxed( \ |
| 55 | iommu_unit->reg_map.hostptr + \ |
| 56 | iommu->iommu_reg_list[KGSL_IOMMU_CTX_##REG].reg_offset +\ |
| 57 | (ctx << KGSL_IOMMU_CTX_SHIFT) + \ |
| 58 | iommu->ctx_offset) |
Shubhraprakash Das | d8cbcd1 | 2012-05-07 16:11:32 -0600 | [diff] [blame] | 59 | |
| 60 | /* Gets the lsb value of pagetable */ |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame^] | 61 | #define KGSL_IOMMMU_PT_LSB(iommu, pt_val) \ |
| 62 | (pt_val & \ |
| 63 | ~(iommu->iommu_reg_list[KGSL_IOMMU_CTX_TTBR0].reg_mask << \ |
| 64 | iommu->iommu_reg_list[KGSL_IOMMU_CTX_TTBR0].reg_shift)) |
Shubhraprakash Das | d8cbcd1 | 2012-05-07 16:11:32 -0600 | [diff] [blame] | 65 | |
Shubhraprakash Das | e9541a3 | 2012-05-09 22:25:55 -0600 | [diff] [blame] | 66 | /* offset at which a nop command is placed in setstate_memory */ |
| 67 | #define KGSL_IOMMU_SETSTATE_NOP_OFFSET 1024 |
| 68 | |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 69 | /* |
| 70 | * struct kgsl_iommu_device - Structure holding data about iommu contexts |
| 71 | * @dev: Device pointer to iommu context |
| 72 | * @attached: Indicates whether this iommu context is presently attached to |
| 73 | * a pagetable/domain or not |
| 74 | * @pt_lsb: The LSB of IOMMU_TTBR0 register which is the pagetable |
| 75 | * register |
| 76 | * @ctx_id: This iommu units context id. It can be either 0 or 1 |
| 77 | * @clk_enabled: If set indicates that iommu clocks of this iommu context |
| 78 | * are on, else the clocks are off |
| 79 | */ |
| 80 | struct kgsl_iommu_device { |
| 81 | struct device *dev; |
| 82 | bool attached; |
| 83 | unsigned int pt_lsb; |
| 84 | enum kgsl_iommu_context_id ctx_id; |
| 85 | bool clk_enabled; |
Jordan Crouse | 95b6847 | 2012-05-25 10:25:01 -0600 | [diff] [blame] | 86 | struct kgsl_device *kgsldev; |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /* |
| 90 | * struct kgsl_iommu_unit - Structure holding data about iommu units. An IOMMU |
| 91 | * units is basically a separte IOMMU h/w block with it's own IOMMU contexts |
| 92 | * @dev: Pointer to array of struct kgsl_iommu_device which has information |
| 93 | * about the IOMMU contexts under this IOMMU unit |
| 94 | * @dev_count: Number of IOMMU contexts that are valid in the previous feild |
| 95 | * @reg_map: Memory descriptor which holds the mapped address of this IOMMU |
| 96 | * units register range |
| 97 | */ |
| 98 | struct kgsl_iommu_unit { |
| 99 | struct kgsl_iommu_device dev[KGSL_IOMMU_MAX_DEVS_PER_UNIT]; |
| 100 | unsigned int dev_count; |
| 101 | struct kgsl_memdesc reg_map; |
| 102 | }; |
| 103 | |
| 104 | /* |
| 105 | * struct kgsl_iommu - Structure holding iommu data for kgsl driver |
| 106 | * @dev: Array of kgsl_iommu_device which contain information about |
| 107 | * iommu contexts owned by graphics cores |
| 108 | * @unit_count: Number of IOMMU units that are available for this |
| 109 | * instance of the IOMMU driver |
| 110 | * @iommu_last_cmd_ts: The timestamp of last command submitted that |
| 111 | * aceeses iommu registers |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 112 | * @clk_event_queued: Indicates whether an event to disable clocks |
| 113 | * is already queued or not |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 114 | * @device: Pointer to kgsl device |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame^] | 115 | * @ctx_offset: The context offset to be added to base address when |
| 116 | * accessing IOMMU registers |
| 117 | * @iommu_reg_list: List of IOMMU registers { offset, map, shift } array |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 118 | */ |
| 119 | struct kgsl_iommu { |
| 120 | struct kgsl_iommu_unit iommu_units[KGSL_IOMMU_MAX_UNITS]; |
| 121 | unsigned int unit_count; |
| 122 | unsigned int iommu_last_cmd_ts; |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 123 | bool clk_event_queued; |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 124 | struct kgsl_device *device; |
Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame^] | 125 | unsigned int ctx_offset; |
| 126 | struct kgsl_iommu_register_list *iommu_reg_list; |
Shubhraprakash Das | d3f937c | 2012-05-07 12:44:40 -0600 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * struct kgsl_iommu_pt - Iommu pagetable structure private to kgsl driver |
| 131 | * @domain: Pointer to the iommu domain that contains the iommu pagetable |
| 132 | * @iommu: Pointer to iommu structure |
Shubhraprakash Das | d3f937c | 2012-05-07 12:44:40 -0600 | [diff] [blame] | 133 | */ |
| 134 | struct kgsl_iommu_pt { |
| 135 | struct iommu_domain *domain; |
| 136 | struct kgsl_iommu *iommu; |
Shubhraprakash Das | eb6df1d | 2012-05-01 00:55:35 -0600 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | #endif |