Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 1 | /* |
Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 2 | * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __LINUX_HOST1X_H |
| 20 | #define __LINUX_HOST1X_H |
| 21 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 22 | #include <linux/device.h> |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 23 | #include <linux/types.h> |
| 24 | |
Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 25 | enum host1x_class { |
Thierry Reding | e1e9064 | 2013-09-24 13:59:01 +0200 | [diff] [blame] | 26 | HOST1X_CLASS_HOST1X = 0x1, |
| 27 | HOST1X_CLASS_GR2D = 0x51, |
| 28 | HOST1X_CLASS_GR2D_SB = 0x52, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 29 | HOST1X_CLASS_GR3D = 0x60, |
Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 30 | }; |
| 31 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 32 | struct host1x_client; |
| 33 | |
| 34 | struct host1x_client_ops { |
| 35 | int (*init)(struct host1x_client *client); |
| 36 | int (*exit)(struct host1x_client *client); |
| 37 | }; |
| 38 | |
| 39 | struct host1x_client { |
| 40 | struct list_head list; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 41 | struct device *parent; |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 42 | struct device *dev; |
| 43 | |
| 44 | const struct host1x_client_ops *ops; |
| 45 | |
| 46 | enum host1x_class class; |
| 47 | struct host1x_channel *channel; |
| 48 | |
| 49 | struct host1x_syncpt **syncpts; |
| 50 | unsigned int num_syncpts; |
| 51 | }; |
| 52 | |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 53 | /* |
| 54 | * host1x buffer objects |
| 55 | */ |
| 56 | |
| 57 | struct host1x_bo; |
| 58 | struct sg_table; |
| 59 | |
| 60 | struct host1x_bo_ops { |
| 61 | struct host1x_bo *(*get)(struct host1x_bo *bo); |
| 62 | void (*put)(struct host1x_bo *bo); |
| 63 | dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt); |
| 64 | void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt); |
| 65 | void *(*mmap)(struct host1x_bo *bo); |
| 66 | void (*munmap)(struct host1x_bo *bo, void *addr); |
| 67 | void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum); |
| 68 | void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr); |
| 69 | }; |
| 70 | |
| 71 | struct host1x_bo { |
| 72 | const struct host1x_bo_ops *ops; |
| 73 | }; |
| 74 | |
| 75 | static inline void host1x_bo_init(struct host1x_bo *bo, |
| 76 | const struct host1x_bo_ops *ops) |
| 77 | { |
| 78 | bo->ops = ops; |
| 79 | } |
| 80 | |
| 81 | static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo) |
| 82 | { |
| 83 | return bo->ops->get(bo); |
| 84 | } |
| 85 | |
| 86 | static inline void host1x_bo_put(struct host1x_bo *bo) |
| 87 | { |
| 88 | bo->ops->put(bo); |
| 89 | } |
| 90 | |
| 91 | static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo, |
| 92 | struct sg_table **sgt) |
| 93 | { |
| 94 | return bo->ops->pin(bo, sgt); |
| 95 | } |
| 96 | |
| 97 | static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt) |
| 98 | { |
| 99 | bo->ops->unpin(bo, sgt); |
| 100 | } |
| 101 | |
| 102 | static inline void *host1x_bo_mmap(struct host1x_bo *bo) |
| 103 | { |
| 104 | return bo->ops->mmap(bo); |
| 105 | } |
| 106 | |
| 107 | static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr) |
| 108 | { |
| 109 | bo->ops->munmap(bo, addr); |
| 110 | } |
| 111 | |
| 112 | static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum) |
| 113 | { |
| 114 | return bo->ops->kmap(bo, pagenum); |
| 115 | } |
| 116 | |
| 117 | static inline void host1x_bo_kunmap(struct host1x_bo *bo, |
| 118 | unsigned int pagenum, void *addr) |
| 119 | { |
| 120 | bo->ops->kunmap(bo, pagenum, addr); |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * host1x syncpoints |
| 125 | */ |
| 126 | |
Arto Merilainen | 8736fe8 | 2013-10-14 15:21:52 +0300 | [diff] [blame] | 127 | #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0) |
Arto Merilainen | f5a954f | 2013-10-14 15:21:53 +0300 | [diff] [blame] | 128 | #define HOST1X_SYNCPT_HAS_BASE (1 << 1) |
Arto Merilainen | 8736fe8 | 2013-10-14 15:21:52 +0300 | [diff] [blame] | 129 | |
Arto Merilainen | f5a954f | 2013-10-14 15:21:53 +0300 | [diff] [blame] | 130 | struct host1x_syncpt_base; |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 131 | struct host1x_syncpt; |
| 132 | struct host1x; |
| 133 | |
| 134 | struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id); |
| 135 | u32 host1x_syncpt_id(struct host1x_syncpt *sp); |
| 136 | u32 host1x_syncpt_read_min(struct host1x_syncpt *sp); |
| 137 | u32 host1x_syncpt_read_max(struct host1x_syncpt *sp); |
Thierry Reding | b4a20144 | 2015-01-28 14:29:02 +0100 | [diff] [blame] | 138 | u32 host1x_syncpt_read(struct host1x_syncpt *sp); |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 139 | int host1x_syncpt_incr(struct host1x_syncpt *sp); |
Bryan Wu | 64400c3 | 2014-02-19 14:48:36 -0800 | [diff] [blame] | 140 | u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs); |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 141 | int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout, |
| 142 | u32 *value); |
| 143 | struct host1x_syncpt *host1x_syncpt_request(struct device *dev, |
Arto Merilainen | 8736fe8 | 2013-10-14 15:21:52 +0300 | [diff] [blame] | 144 | unsigned long flags); |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 145 | void host1x_syncpt_free(struct host1x_syncpt *sp); |
| 146 | |
Arto Merilainen | f5a954f | 2013-10-14 15:21:53 +0300 | [diff] [blame] | 147 | struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp); |
| 148 | u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base); |
| 149 | |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 150 | /* |
| 151 | * host1x channel |
| 152 | */ |
| 153 | |
| 154 | struct host1x_channel; |
| 155 | struct host1x_job; |
| 156 | |
| 157 | struct host1x_channel *host1x_channel_request(struct device *dev); |
| 158 | void host1x_channel_free(struct host1x_channel *channel); |
| 159 | struct host1x_channel *host1x_channel_get(struct host1x_channel *channel); |
| 160 | void host1x_channel_put(struct host1x_channel *channel); |
| 161 | int host1x_job_submit(struct host1x_job *job); |
| 162 | |
| 163 | /* |
| 164 | * host1x job |
| 165 | */ |
| 166 | |
| 167 | struct host1x_reloc { |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 168 | struct { |
| 169 | struct host1x_bo *bo; |
| 170 | unsigned long offset; |
| 171 | } cmdbuf; |
| 172 | struct { |
| 173 | struct host1x_bo *bo; |
| 174 | unsigned long offset; |
| 175 | } target; |
| 176 | unsigned long shift; |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | struct host1x_job { |
| 180 | /* When refcount goes to zero, job can be freed */ |
| 181 | struct kref ref; |
| 182 | |
| 183 | /* List entry */ |
| 184 | struct list_head list; |
| 185 | |
| 186 | /* Channel where job is submitted to */ |
| 187 | struct host1x_channel *channel; |
| 188 | |
| 189 | u32 client; |
| 190 | |
| 191 | /* Gathers and their memory */ |
| 192 | struct host1x_job_gather *gathers; |
| 193 | unsigned int num_gathers; |
| 194 | |
| 195 | /* Wait checks to be processed at submit time */ |
| 196 | struct host1x_waitchk *waitchk; |
| 197 | unsigned int num_waitchk; |
| 198 | u32 waitchk_mask; |
| 199 | |
| 200 | /* Array of handles to be pinned & unpinned */ |
| 201 | struct host1x_reloc *relocarray; |
| 202 | unsigned int num_relocs; |
| 203 | struct host1x_job_unpin_data *unpins; |
| 204 | unsigned int num_unpins; |
| 205 | |
| 206 | dma_addr_t *addr_phys; |
| 207 | dma_addr_t *gather_addr_phys; |
| 208 | dma_addr_t *reloc_addr_phys; |
| 209 | |
| 210 | /* Sync point id, number of increments and end related to the submit */ |
| 211 | u32 syncpt_id; |
| 212 | u32 syncpt_incrs; |
| 213 | u32 syncpt_end; |
| 214 | |
| 215 | /* Maximum time to wait for this job */ |
| 216 | unsigned int timeout; |
| 217 | |
| 218 | /* Index and number of slots used in the push buffer */ |
| 219 | unsigned int first_get; |
| 220 | unsigned int num_slots; |
| 221 | |
| 222 | /* Copy of gathers */ |
| 223 | size_t gather_copy_size; |
| 224 | dma_addr_t gather_copy; |
| 225 | u8 *gather_copy_mapped; |
| 226 | |
| 227 | /* Check if register is marked as an address reg */ |
| 228 | int (*is_addr_reg)(struct device *dev, u32 reg, u32 class); |
| 229 | |
| 230 | /* Request a SETCLASS to this class */ |
| 231 | u32 class; |
| 232 | |
| 233 | /* Add a channel wait for previous ops to complete */ |
| 234 | bool serialize; |
| 235 | }; |
| 236 | |
| 237 | struct host1x_job *host1x_job_alloc(struct host1x_channel *ch, |
| 238 | u32 num_cmdbufs, u32 num_relocs, |
| 239 | u32 num_waitchks); |
| 240 | void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id, |
| 241 | u32 words, u32 offset); |
| 242 | struct host1x_job *host1x_job_get(struct host1x_job *job); |
| 243 | void host1x_job_put(struct host1x_job *job); |
| 244 | int host1x_job_pin(struct host1x_job *job, struct device *dev); |
| 245 | void host1x_job_unpin(struct host1x_job *job); |
| 246 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 247 | /* |
| 248 | * subdevice probe infrastructure |
| 249 | */ |
| 250 | |
| 251 | struct host1x_device; |
| 252 | |
| 253 | struct host1x_driver { |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 254 | struct device_driver driver; |
| 255 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 256 | const struct of_device_id *subdevs; |
| 257 | struct list_head list; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 258 | |
| 259 | int (*probe)(struct host1x_device *device); |
| 260 | int (*remove)(struct host1x_device *device); |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 261 | void (*shutdown)(struct host1x_device *device); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 262 | }; |
| 263 | |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 264 | static inline struct host1x_driver * |
| 265 | to_host1x_driver(struct device_driver *driver) |
| 266 | { |
| 267 | return container_of(driver, struct host1x_driver, driver); |
| 268 | } |
| 269 | |
| 270 | int host1x_driver_register_full(struct host1x_driver *driver, |
| 271 | struct module *owner); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 272 | void host1x_driver_unregister(struct host1x_driver *driver); |
| 273 | |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 274 | #define host1x_driver_register(driver) \ |
| 275 | host1x_driver_register_full(driver, THIS_MODULE) |
| 276 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 277 | struct host1x_device { |
| 278 | struct host1x_driver *driver; |
| 279 | struct list_head list; |
| 280 | struct device dev; |
| 281 | |
| 282 | struct mutex subdevs_lock; |
| 283 | struct list_head subdevs; |
| 284 | struct list_head active; |
| 285 | |
| 286 | struct mutex clients_lock; |
| 287 | struct list_head clients; |
Thierry Reding | 536e171 | 2014-11-05 11:43:26 +0100 | [diff] [blame] | 288 | |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 289 | bool registered; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 290 | }; |
| 291 | |
| 292 | static inline struct host1x_device *to_host1x_device(struct device *dev) |
| 293 | { |
| 294 | return container_of(dev, struct host1x_device, dev); |
| 295 | } |
| 296 | |
| 297 | int host1x_device_init(struct host1x_device *device); |
| 298 | int host1x_device_exit(struct host1x_device *device); |
| 299 | |
| 300 | int host1x_client_register(struct host1x_client *client); |
| 301 | int host1x_client_unregister(struct host1x_client *client); |
| 302 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 303 | struct tegra_mipi_device; |
| 304 | |
| 305 | struct tegra_mipi_device *tegra_mipi_request(struct device *device); |
| 306 | void tegra_mipi_free(struct tegra_mipi_device *device); |
Thierry Reding | 87904c3 | 2016-08-12 16:00:53 +0200 | [diff] [blame] | 307 | int tegra_mipi_enable(struct tegra_mipi_device *device); |
| 308 | int tegra_mipi_disable(struct tegra_mipi_device *device); |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 309 | int tegra_mipi_calibrate(struct tegra_mipi_device *device); |
| 310 | |
Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 311 | #endif |