blob: 7dc222e8cd73f02849e2de9662de8c840eaf2b5b [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
19#define KGSL_IOMMU_CTX_SHIFT 12
Jordan Crouse95b68472012-05-25 10:25:01 -060020
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -070021enum 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
30struct kgsl_iommu_register_list {
31 unsigned int reg_offset;
32 unsigned int reg_mask;
33 unsigned int reg_shift;
34};
Shubhraprakash Dasd3f937c2012-05-07 12:44:40 -060035
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -060036/*
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 Dasd8cbcd12012-05-07 16:11:32 -060045/* Macros to read/write IOMMU registers */
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -070046#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 Dasd8cbcd12012-05-07 16:11:32 -060052
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -070053#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 Dasd8cbcd12012-05-07 16:11:32 -060059
60/* Gets the lsb value of pagetable */
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -070061#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 Dasd8cbcd12012-05-07 16:11:32 -060065
Shubhraprakash Dase9541a32012-05-09 22:25:55 -060066/* offset at which a nop command is placed in setstate_memory */
67#define KGSL_IOMMU_SETSTATE_NOP_OFFSET 1024
68
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -060069/*
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 */
80struct 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 Crouse95b68472012-05-25 10:25:01 -060086 struct kgsl_device *kgsldev;
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -060087};
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 */
98struct 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 Dascb068072012-06-07 17:52:41 -0600112 * @clk_event_queued: Indicates whether an event to disable clocks
113 * is already queued or not
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -0600114 * @device: Pointer to kgsl device
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -0700115 * @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 Daseb6df1d2012-05-01 00:55:35 -0600118 */
119struct 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 Dascb068072012-06-07 17:52:41 -0600123 bool clk_event_queued;
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -0600124 struct kgsl_device *device;
Shubhraprakash Das3cf33be2012-08-16 22:42:55 -0700125 unsigned int ctx_offset;
126 struct kgsl_iommu_register_list *iommu_reg_list;
Shubhraprakash Dasd3f937c2012-05-07 12:44:40 -0600127};
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 Dasd3f937c2012-05-07 12:44:40 -0600133 */
134struct kgsl_iommu_pt {
135 struct iommu_domain *domain;
136 struct kgsl_iommu *iommu;
Shubhraprakash Daseb6df1d2012-05-01 00:55:35 -0600137};
138
139#endif