Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2008-2011, 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_H |
| 14 | #define __KGSL_H |
| 15 | |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/msm_kgsl.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/clk.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/mutex.h> |
| 22 | #include <linux/cdev.h> |
| 23 | #include <linux/regulator/consumer.h> |
| 24 | |
| 25 | #define KGSL_NAME "kgsl" |
| 26 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | /*cache coherency ops */ |
| 28 | #define DRM_KGSL_GEM_CACHE_OP_TO_DEV 0x0001 |
| 29 | #define DRM_KGSL_GEM_CACHE_OP_FROM_DEV 0x0002 |
| 30 | |
| 31 | /* The size of each entry in a page table */ |
| 32 | #define KGSL_PAGETABLE_ENTRY_SIZE 4 |
| 33 | |
| 34 | /* Pagetable Virtual Address base */ |
| 35 | #define KGSL_PAGETABLE_BASE 0x66000000 |
| 36 | |
| 37 | /* Extra accounting entries needed in the pagetable */ |
| 38 | #define KGSL_PT_EXTRA_ENTRIES 16 |
| 39 | |
| 40 | #define KGSL_PAGETABLE_ENTRIES(_sz) (((_sz) >> PAGE_SHIFT) + \ |
| 41 | KGSL_PT_EXTRA_ENTRIES) |
| 42 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 43 | #define KGSL_PAGETABLE_SIZE \ |
| 44 | ALIGN(KGSL_PAGETABLE_ENTRIES(CONFIG_MSM_KGSL_PAGE_TABLE_SIZE) * \ |
| 45 | KGSL_PAGETABLE_ENTRY_SIZE, PAGE_SIZE) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | |
| 47 | #ifdef CONFIG_KGSL_PER_PROCESS_PAGE_TABLE |
| 48 | #define KGSL_PAGETABLE_COUNT (CONFIG_MSM_KGSL_PAGE_TABLE_COUNT) |
| 49 | #else |
| 50 | #define KGSL_PAGETABLE_COUNT 1 |
| 51 | #endif |
| 52 | |
| 53 | /* Casting using container_of() for structures that kgsl owns. */ |
| 54 | #define KGSL_CONTAINER_OF(ptr, type, member) \ |
| 55 | container_of(ptr, type, member) |
| 56 | |
| 57 | /* A macro for memory statistics - add the new size to the stat and if |
| 58 | the statisic is greater then _max, set _max |
| 59 | */ |
| 60 | |
| 61 | #define KGSL_STATS_ADD(_size, _stat, _max) \ |
| 62 | do { _stat += (_size); if (_stat > _max) _max = _stat; } while (0) |
| 63 | |
| 64 | struct kgsl_device; |
| 65 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 66 | struct kgsl_driver { |
| 67 | struct cdev cdev; |
| 68 | dev_t major; |
| 69 | struct class *class; |
| 70 | /* Virtual device for managing the core */ |
| 71 | struct device virtdev; |
| 72 | /* Kobjects for storing pagetable and process statistics */ |
| 73 | struct kobject *ptkobj; |
| 74 | struct kobject *prockobj; |
| 75 | struct kgsl_device *devp[KGSL_DEVICE_MAX]; |
| 76 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 77 | /* Global lilst of open processes */ |
| 78 | struct list_head process_list; |
| 79 | /* Global list of pagetables */ |
| 80 | struct list_head pagetable_list; |
| 81 | /* Spinlock for accessing the pagetable list */ |
| 82 | spinlock_t ptlock; |
| 83 | /* Mutex for accessing the process list */ |
| 84 | struct mutex process_mutex; |
| 85 | |
| 86 | /* Mutex for protecting the device list */ |
| 87 | struct mutex devlock; |
| 88 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 89 | void *ptpool; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 90 | |
| 91 | struct { |
| 92 | unsigned int vmalloc; |
| 93 | unsigned int vmalloc_max; |
| 94 | unsigned int coherent; |
| 95 | unsigned int coherent_max; |
| 96 | unsigned int mapped; |
| 97 | unsigned int mapped_max; |
| 98 | unsigned int histogram[16]; |
| 99 | } stats; |
| 100 | }; |
| 101 | |
| 102 | extern struct kgsl_driver kgsl_driver; |
| 103 | |
| 104 | #define KGSL_USER_MEMORY 1 |
| 105 | #define KGSL_MAPPED_MEMORY 2 |
| 106 | |
| 107 | struct kgsl_pagetable; |
| 108 | struct kgsl_memdesc_ops; |
| 109 | |
| 110 | /* shared memory allocation */ |
| 111 | struct kgsl_memdesc { |
| 112 | struct kgsl_pagetable *pagetable; |
| 113 | void *hostptr; |
| 114 | unsigned int gpuaddr; |
| 115 | unsigned int physaddr; |
| 116 | unsigned int size; |
| 117 | unsigned int priv; |
Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame^] | 118 | struct scatterlist *sg; |
| 119 | unsigned int sglen; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 120 | struct kgsl_memdesc_ops *ops; |
| 121 | }; |
| 122 | |
| 123 | struct kgsl_mem_entry { |
| 124 | struct kref refcount; |
| 125 | struct kgsl_memdesc memdesc; |
| 126 | int memtype; |
| 127 | struct file *file_ptr; |
| 128 | struct list_head list; |
| 129 | uint32_t free_timestamp; |
| 130 | /* back pointer to private structure under whose context this |
| 131 | * allocation is made */ |
| 132 | struct kgsl_process_private *priv; |
| 133 | }; |
| 134 | |
| 135 | #ifdef CONFIG_MSM_KGSL_MMU_PAGE_FAULT |
| 136 | #define MMU_CONFIG 2 |
| 137 | #else |
| 138 | #define MMU_CONFIG 1 |
| 139 | #endif |
| 140 | |
| 141 | void kgsl_mem_entry_destroy(struct kref *kref); |
| 142 | uint8_t *kgsl_gpuaddr_to_vaddr(const struct kgsl_memdesc *memdesc, |
| 143 | unsigned int gpuaddr, unsigned int *size); |
| 144 | struct kgsl_mem_entry *kgsl_sharedmem_find_region( |
| 145 | struct kgsl_process_private *private, unsigned int gpuaddr, |
| 146 | size_t size); |
| 147 | |
| 148 | extern const struct dev_pm_ops kgsl_pm_ops; |
| 149 | |
| 150 | struct early_suspend; |
| 151 | int kgsl_suspend_driver(struct platform_device *pdev, pm_message_t state); |
| 152 | int kgsl_resume_driver(struct platform_device *pdev); |
| 153 | void kgsl_early_suspend_driver(struct early_suspend *h); |
| 154 | void kgsl_late_resume_driver(struct early_suspend *h); |
| 155 | |
| 156 | #ifdef CONFIG_MSM_KGSL_DRM |
| 157 | extern int kgsl_drm_init(struct platform_device *dev); |
| 158 | extern void kgsl_drm_exit(void); |
| 159 | extern void kgsl_gpu_mem_flush(int op); |
| 160 | #else |
| 161 | static inline int kgsl_drm_init(struct platform_device *dev) |
| 162 | { |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static inline void kgsl_drm_exit(void) |
| 167 | { |
| 168 | } |
| 169 | #endif |
| 170 | |
| 171 | static inline int kgsl_gpuaddr_in_memdesc(const struct kgsl_memdesc *memdesc, |
| 172 | unsigned int gpuaddr) |
| 173 | { |
| 174 | if (gpuaddr >= memdesc->gpuaddr && (gpuaddr + sizeof(unsigned int)) <= |
| 175 | (memdesc->gpuaddr + memdesc->size)) { |
| 176 | return 1; |
| 177 | } |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | static inline bool timestamp_cmp(unsigned int new, unsigned int old) |
| 182 | { |
| 183 | int ts_diff = new - old; |
| 184 | return (ts_diff >= 0) || (ts_diff < -20000); |
| 185 | } |
| 186 | |
| 187 | static inline void |
| 188 | kgsl_mem_entry_get(struct kgsl_mem_entry *entry) |
| 189 | { |
| 190 | kref_get(&entry->refcount); |
| 191 | } |
| 192 | |
| 193 | static inline void |
| 194 | kgsl_mem_entry_put(struct kgsl_mem_entry *entry) |
| 195 | { |
| 196 | kref_put(&entry->refcount, kgsl_mem_entry_destroy); |
| 197 | } |
| 198 | |
| 199 | #endif /* __KGSL_H */ |