PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/gpu/msm/kgsl.h

https://gitlab.com/TeamTators/hp-kernel-tenderloin
C Header | 233 lines | 148 code | 44 blank | 41 comment | 6 complexity | ad1f7806366c2173d8c307a2a3cd73b0 MD5 | raw file
  1/* Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved.
  2 *
  3 * Redistribution and use in source and binary forms, with or without
  4 * modification, are permitted provided that the following conditions are
  5 * met:
  6 *     * Redistributions of source code must retain the above copyright
  7 *       notice, this list of conditions and the following disclaimer.
  8 *     * Redistributions in binary form must reproduce the above
  9 *       copyright notice, this list of conditions and the following
 10 *       disclaimer in the documentation and/or other materials provided
 11 *       with the distribution.
 12 *     * Neither the name of Code Aurora Forum, Inc. nor the names of its
 13 *       contributors may be used to endorse or promote products derived
 14 *       from this software without specific prior written permission.
 15 *
 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 *
 28 */
 29#ifndef _GSL_DRIVER_H
 30#define _GSL_DRIVER_H
 31
 32#include <linux/types.h>
 33#include <linux/msm_kgsl.h>
 34#include <linux/platform_device.h>
 35#include <linux/clk.h>
 36#include <linux/mutex.h>
 37#include <linux/cdev.h>
 38#include <linux/regulator/consumer.h>
 39
 40#include <asm/atomic.h>
 41
 42#include "kgsl_device.h"
 43#include "kgsl_sharedmem.h"
 44
 45#define DRIVER_NAME "kgsl"
 46#define CLASS_NAME "msm_kgsl"
 47#define CHIP_REV_251 0x020501
 48
 49/* Flags to control whether to flush or invalidate a cached memory range */
 50#define KGSL_CACHE_INV		0x00000000
 51#define KGSL_CACHE_CLEAN	0x00000001
 52#define KGSL_CACHE_FLUSH	0x00000002
 53
 54#define KGSL_CACHE_USER_ADDR	0x00000010
 55#define KGSL_CACHE_VMALLOC_ADDR	0x00000020
 56
 57/*cache coherency ops */
 58#define DRM_KGSL_GEM_CACHE_OP_TO_DEV	0x0001
 59#define DRM_KGSL_GEM_CACHE_OP_FROM_DEV	0x0002
 60
 61#define KGSL_NUM_2D_DEVICES 2
 62#define IDX_2D(X) ((X)-KGSL_DEVICE_2D0)
 63
 64/* The size of each entry in a page table */
 65#define KGSL_PAGETABLE_ENTRY_SIZE  4
 66
 67/* Pagetable Virtual Address base */
 68#define KGSL_PAGETABLE_BASE	0x66000000
 69
 70/* Extra accounting entries needed in the pagetable */
 71#define KGSL_PT_EXTRA_ENTRIES      16
 72
 73#define KGSL_PAGETABLE_ENTRIES(_sz) (((_sz) >> KGSL_PAGESIZE_SHIFT) + \
 74				     KGSL_PT_EXTRA_ENTRIES)
 75
 76#ifdef CONFIG_KGSL_PER_PROCESS_PAGE_TABLE
 77#define KGSL_PAGETABLE_COUNT (CONFIG_MSM_KGSL_PAGE_TABLE_COUNT)
 78#else
 79#define KGSL_PAGETABLE_COUNT 1
 80#endif
 81
 82/* Casting using container_of() for structures that kgsl owns. */
 83#define KGSL_CONTAINER_OF(ptr, type, member) \
 84		container_of(ptr, type, member)
 85#define KGSL_YAMATO_DEVICE(device) \
 86		KGSL_CONTAINER_OF(device, struct kgsl_yamato_device, dev)
 87#define KGSL_G12_DEVICE(device) \
 88		KGSL_CONTAINER_OF(device, struct kgsl_g12_device, dev)
 89
 90struct kgsl_driver {
 91	struct cdev cdev;
 92	dev_t dev_num;
 93	struct class *class;
 94	struct kgsl_device *devp[KGSL_DEVICE_MAX];
 95	int num_devs;
 96	struct platform_device *pdev;
 97
 98	uint32_t flags_debug;
 99
100	/* Global lilst of open processes */
101	struct list_head process_list;
102	/* Global list of pagetables */
103	struct list_head pagetable_list;
104	/* Mutex for accessing the pagetable list */
105	struct mutex pt_mutex;
106	/* Mutex for accessing the process list */
107	struct mutex process_mutex;
108
109	struct kgsl_pagetable *global_pt;
110
111	/* Size (in bytes) for each pagetable */
112	unsigned int ptsize;
113
114	struct kgsl_ptpool ptpool;
115
116};
117
118extern struct kgsl_driver kgsl_driver;
119
120struct kgsl_mem_entry {
121	struct kgsl_memdesc memdesc;
122	struct file *file_ptr;
123	struct list_head list;
124	uint32_t free_timestamp;
125	/* back pointer to private structure under whose context this
126	* allocation is made */
127	struct kgsl_process_private *priv;
128};
129
130enum kgsl_status {
131	KGSL_SUCCESS = 0,
132	KGSL_FAILURE = 1
133};
134
135#define KGSL_TRUE 1
136#define KGSL_FALSE 0
137
138#ifdef CONFIG_MSM_KGSL_MMU_PAGE_FAULT
139#define MMU_CONFIG 2
140#else
141#define MMU_CONFIG 1
142#endif
143
144void kgsl_destroy_mem_entry(struct kgsl_mem_entry *entry);
145uint8_t *kgsl_gpuaddr_to_vaddr(const struct kgsl_memdesc *memdesc,
146	unsigned int gpuaddr, unsigned int *size);
147struct kgsl_mem_entry *kgsl_sharedmem_find_region(
148	struct kgsl_process_private *private, unsigned int gpuaddr,
149	size_t size);
150uint8_t *kgsl_sharedmem_convertaddr(struct kgsl_device *device,
151	unsigned int pt_base, unsigned int gpuaddr, unsigned int *size);
152int kgsl_idle(struct kgsl_device *device, unsigned int timeout);
153int kgsl_setstate(struct kgsl_device *device, uint32_t flags);
154
155static inline void kgsl_regread(struct kgsl_device *device,
156				unsigned int offsetwords,
157				unsigned int *value)
158{
159	device->ftbl.device_regread(device, offsetwords, value);
160}
161
162static inline void kgsl_regwrite(struct kgsl_device *device,
163				 unsigned int offsetwords,
164				 unsigned int value)
165{
166	device->ftbl.device_regwrite(device, offsetwords, value);
167}
168
169static inline void kgsl_regread_isr(struct kgsl_device *device,
170				    unsigned int offsetwords,
171				    unsigned int *value)
172{
173	device->ftbl.device_regread_isr(device, offsetwords, value);
174}
175
176static inline void kgsl_regwrite_isr(struct kgsl_device *device,
177				      unsigned int offsetwords,
178				      unsigned int value)
179{
180	device->ftbl.device_regwrite_isr(device, offsetwords, value);
181}
182
183int kgsl_check_timestamp(struct kgsl_device *device, unsigned int timestamp);
184
185int kgsl_setup_pt(struct kgsl_pagetable *);
186
187int kgsl_cleanup_pt(struct kgsl_pagetable *);
188
189int kgsl_register_ts_notifier(struct kgsl_device *device,
190			      struct notifier_block *nb);
191
192int kgsl_unregister_ts_notifier(struct kgsl_device *device,
193				struct notifier_block *nb);
194
195#ifdef CONFIG_MSM_KGSL_DRM
196extern int kgsl_drm_init(struct platform_device *dev);
197extern void kgsl_drm_exit(void);
198extern void kgsl_gpu_mem_flush(int op);
199#else
200static inline int kgsl_drm_init(struct platform_device *dev)
201{
202	return 0;
203}
204
205static inline void kgsl_drm_exit(void)
206{
207}
208#endif
209
210static inline int kgsl_gpuaddr_in_memdesc(const struct kgsl_memdesc *memdesc,
211				unsigned int gpuaddr)
212{
213	if (gpuaddr >= memdesc->gpuaddr && (gpuaddr + sizeof(unsigned int)) <=
214		(memdesc->gpuaddr + memdesc->size)) {
215		return 1;
216	}
217	return 0;
218}
219
220static inline struct kgsl_device *kgsl_device_from_dev(struct device *dev)
221{
222	int i;
223
224	for (i = 0; i < KGSL_DEVICE_MAX; i++) {
225		if (kgsl_driver.devp[i] && kgsl_driver.devp[i]->dev == dev)
226			return kgsl_driver.devp[i];
227	}
228
229	return NULL;
230}
231
232
233#endif /* _GSL_DRIVER_H */