blob: eafba7bc249481a0cefc508825c9960eb5bab73e [file] [log] [blame]
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -06001/* 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 Das3cf33be2012-08-16 22:42:55 -070018#define KGSL_IOMMU_CTX_OFFSET_V1 0
Shubhraprakash Das15a8b462012-08-16 23:24:28 -070019#define KGSL_IOMMU_CTX_OFFSET_V2 0x8000
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -070020#define KGSL_IOMMU_CTX_SHIFT 12
Jordan Crouse95b68472012-05-25 10:25:01 -060021
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -070022enum kgsl_iommu_reg_map {
23 KGSL_IOMMU_GLOBAL_BASE = 0,
24 KGSL_IOMMU_CTX_TTBR0,
25 KGSL_IOMMU_CTX_TTBR1,
26 KGSL_IOMMU_CTX_FSR,
27 KGSL_IOMMU_CTX_TLBIALL,
28 KGSL_IOMMU_REG_MAX
29};
30
31struct kgsl_iommu_register_list {
32 unsigned int reg_offset;
33 unsigned int reg_mask;
34 unsigned int reg_shift;
35};
Shubhraprakash Dasd3f937c2012-05-07 12:44:40 -060036
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -060037/*
38 * Max number of iommu units that the gpu core can have
39 * On APQ8064, KGSL can control a maximum of 2 IOMMU units.
40 */
41#define KGSL_IOMMU_MAX_UNITS 2
42
43/* Max number of iommu contexts per IOMMU unit */
44#define KGSL_IOMMU_MAX_DEVS_PER_UNIT 2
45
Shubhraprakash Dasd8cbcd12012-05-07 16:11:32 -060046/* Macros to read/write IOMMU registers */
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -070047#define KGSL_IOMMU_SET_CTX_REG(iommu, iommu_unit, ctx, REG, val) \
48 writel_relaxed(val, \
49 iommu_unit->reg_map.hostptr + \
50 iommu->iommu_reg_list[KGSL_IOMMU_CTX_##REG].reg_offset +\
51 (ctx << KGSL_IOMMU_CTX_SHIFT) + \
52 iommu->ctx_offset)
Shubhraprakash Dasd8cbcd12012-05-07 16:11:32 -060053
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -070054#define KGSL_IOMMU_GET_CTX_REG(iommu, iommu_unit, ctx, REG) \
55 readl_relaxed( \
56 iommu_unit->reg_map.hostptr + \
57 iommu->iommu_reg_list[KGSL_IOMMU_CTX_##REG].reg_offset +\
58 (ctx << KGSL_IOMMU_CTX_SHIFT) + \
59 iommu->ctx_offset)
Shubhraprakash Dasd8cbcd12012-05-07 16:11:32 -060060
61/* Gets the lsb value of pagetable */
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -070062#define KGSL_IOMMMU_PT_LSB(iommu, pt_val) \
63 (pt_val & \
64 ~(iommu->iommu_reg_list[KGSL_IOMMU_CTX_TTBR0].reg_mask << \
65 iommu->iommu_reg_list[KGSL_IOMMU_CTX_TTBR0].reg_shift))
Shubhraprakash Dasd8cbcd12012-05-07 16:11:32 -060066
Shubhraprakash Dase9541a32012-05-09 22:25:55 -060067/* offset at which a nop command is placed in setstate_memory */
68#define KGSL_IOMMU_SETSTATE_NOP_OFFSET 1024
69
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -060070/*
71 * struct kgsl_iommu_device - Structure holding data about iommu contexts
72 * @dev: Device pointer to iommu context
73 * @attached: Indicates whether this iommu context is presently attached to
74 * a pagetable/domain or not
75 * @pt_lsb: The LSB of IOMMU_TTBR0 register which is the pagetable
76 * register
77 * @ctx_id: This iommu units context id. It can be either 0 or 1
78 * @clk_enabled: If set indicates that iommu clocks of this iommu context
79 * are on, else the clocks are off
80 */
81struct kgsl_iommu_device {
82 struct device *dev;
83 bool attached;
84 unsigned int pt_lsb;
85 enum kgsl_iommu_context_id ctx_id;
86 bool clk_enabled;
Jordan Crouse95b68472012-05-25 10:25:01 -060087 struct kgsl_device *kgsldev;
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -060088};
89
90/*
91 * struct kgsl_iommu_unit - Structure holding data about iommu units. An IOMMU
92 * units is basically a separte IOMMU h/w block with it's own IOMMU contexts
93 * @dev: Pointer to array of struct kgsl_iommu_device which has information
94 * about the IOMMU contexts under this IOMMU unit
95 * @dev_count: Number of IOMMU contexts that are valid in the previous feild
96 * @reg_map: Memory descriptor which holds the mapped address of this IOMMU
97 * units register range
98 */
99struct kgsl_iommu_unit {
100 struct kgsl_iommu_device dev[KGSL_IOMMU_MAX_DEVS_PER_UNIT];
101 unsigned int dev_count;
102 struct kgsl_memdesc reg_map;
103};
104
105/*
106 * struct kgsl_iommu - Structure holding iommu data for kgsl driver
107 * @dev: Array of kgsl_iommu_device which contain information about
108 * iommu contexts owned by graphics cores
109 * @unit_count: Number of IOMMU units that are available for this
110 * instance of the IOMMU driver
111 * @iommu_last_cmd_ts: The timestamp of last command submitted that
112 * aceeses iommu registers
Shubhraprakash Dascb068072012-06-07 17:52:41 -0600113 * @clk_event_queued: Indicates whether an event to disable clocks
114 * is already queued or not
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -0600115 * @device: Pointer to kgsl device
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -0700116 * @ctx_offset: The context offset to be added to base address when
117 * accessing IOMMU registers
118 * @iommu_reg_list: List of IOMMU registers { offset, map, shift } array
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -0600119 */
120struct kgsl_iommu {
121 struct kgsl_iommu_unit iommu_units[KGSL_IOMMU_MAX_UNITS];
122 unsigned int unit_count;
123 unsigned int iommu_last_cmd_ts;
Shubhraprakash Dascb068072012-06-07 17:52:41 -0600124 bool clk_event_queued;
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -0600125 struct kgsl_device *device;
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -0700126 unsigned int ctx_offset;
127 struct kgsl_iommu_register_list *iommu_reg_list;
Shubhraprakash Dasd3f937c2012-05-07 12:44:40 -0600128};
129
130/*
131 * struct kgsl_iommu_pt - Iommu pagetable structure private to kgsl driver
132 * @domain: Pointer to the iommu domain that contains the iommu pagetable
133 * @iommu: Pointer to iommu structure
Shubhraprakash Dasd3f937c2012-05-07 12:44:40 -0600134 */
135struct kgsl_iommu_pt {
136 struct iommu_domain *domain;
137 struct kgsl_iommu *iommu;
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -0600138};
139
140#endif