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, |
Arto Merilainen | 0ae797a | 2016-12-14 13:16:13 +0200 | [diff] [blame] | 29 | HOST1X_CLASS_VIC = 0x5D, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 30 | HOST1X_CLASS_GR3D = 0x60, |
Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 31 | }; |
| 32 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 33 | struct host1x_client; |
| 34 | |
Thierry Reding | 466749f | 2017-04-10 12:27:01 +0200 | [diff] [blame] | 35 | /** |
| 36 | * struct host1x_client_ops - host1x client operations |
| 37 | * @init: host1x client initialization code |
| 38 | * @exit: host1x client tear down code |
| 39 | */ |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 40 | struct host1x_client_ops { |
| 41 | int (*init)(struct host1x_client *client); |
| 42 | int (*exit)(struct host1x_client *client); |
| 43 | }; |
| 44 | |
Thierry Reding | 466749f | 2017-04-10 12:27:01 +0200 | [diff] [blame] | 45 | /** |
| 46 | * struct host1x_client - host1x client structure |
| 47 | * @list: list node for the host1x client |
| 48 | * @parent: pointer to struct device representing the host1x controller |
| 49 | * @dev: pointer to struct device backing this host1x client |
| 50 | * @ops: host1x client operations |
| 51 | * @class: host1x class represented by this client |
| 52 | * @channel: host1x channel associated with this client |
| 53 | * @syncpts: array of syncpoints requested for this client |
| 54 | * @num_syncpts: number of syncpoints requested for this client |
| 55 | */ |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 56 | struct host1x_client { |
| 57 | struct list_head list; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 58 | struct device *parent; |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 59 | struct device *dev; |
| 60 | |
| 61 | const struct host1x_client_ops *ops; |
| 62 | |
| 63 | enum host1x_class class; |
| 64 | struct host1x_channel *channel; |
| 65 | |
| 66 | struct host1x_syncpt **syncpts; |
| 67 | unsigned int num_syncpts; |
| 68 | }; |
| 69 | |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 70 | /* |
| 71 | * host1x buffer objects |
| 72 | */ |
| 73 | |
| 74 | struct host1x_bo; |
| 75 | struct sg_table; |
| 76 | |
| 77 | struct host1x_bo_ops { |
| 78 | struct host1x_bo *(*get)(struct host1x_bo *bo); |
| 79 | void (*put)(struct host1x_bo *bo); |
| 80 | dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt); |
| 81 | void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt); |
| 82 | void *(*mmap)(struct host1x_bo *bo); |
| 83 | void (*munmap)(struct host1x_bo *bo, void *addr); |
| 84 | void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum); |
| 85 | void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr); |
| 86 | }; |
| 87 | |
| 88 | struct host1x_bo { |
| 89 | const struct host1x_bo_ops *ops; |
| 90 | }; |
| 91 | |
| 92 | static inline void host1x_bo_init(struct host1x_bo *bo, |
| 93 | const struct host1x_bo_ops *ops) |
| 94 | { |
| 95 | bo->ops = ops; |
| 96 | } |
| 97 | |
| 98 | static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo) |
| 99 | { |
| 100 | return bo->ops->get(bo); |
| 101 | } |
| 102 | |
| 103 | static inline void host1x_bo_put(struct host1x_bo *bo) |
| 104 | { |
| 105 | bo->ops->put(bo); |
| 106 | } |
| 107 | |
| 108 | static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo, |
| 109 | struct sg_table **sgt) |
| 110 | { |
| 111 | return bo->ops->pin(bo, sgt); |
| 112 | } |
| 113 | |
| 114 | static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt) |
| 115 | { |
| 116 | bo->ops->unpin(bo, sgt); |
| 117 | } |
| 118 | |
| 119 | static inline void *host1x_bo_mmap(struct host1x_bo *bo) |
| 120 | { |
| 121 | return bo->ops->mmap(bo); |
| 122 | } |
| 123 | |
| 124 | static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr) |
| 125 | { |
| 126 | bo->ops->munmap(bo, addr); |
| 127 | } |
| 128 | |
| 129 | static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum) |
| 130 | { |
| 131 | return bo->ops->kmap(bo, pagenum); |
| 132 | } |
| 133 | |
| 134 | static inline void host1x_bo_kunmap(struct host1x_bo *bo, |
| 135 | unsigned int pagenum, void *addr) |
| 136 | { |
| 137 | bo->ops->kunmap(bo, pagenum, addr); |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * host1x syncpoints |
| 142 | */ |
| 143 | |
Arto Merilainen | 8736fe8 | 2013-10-14 15:21:52 +0300 | [diff] [blame] | 144 | #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0) |
Arto Merilainen | f5a954f | 2013-10-14 15:21:53 +0300 | [diff] [blame] | 145 | #define HOST1X_SYNCPT_HAS_BASE (1 << 1) |
Arto Merilainen | 8736fe8 | 2013-10-14 15:21:52 +0300 | [diff] [blame] | 146 | |
Arto Merilainen | f5a954f | 2013-10-14 15:21:53 +0300 | [diff] [blame] | 147 | struct host1x_syncpt_base; |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 148 | struct host1x_syncpt; |
| 149 | struct host1x; |
| 150 | |
| 151 | struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id); |
| 152 | u32 host1x_syncpt_id(struct host1x_syncpt *sp); |
| 153 | u32 host1x_syncpt_read_min(struct host1x_syncpt *sp); |
| 154 | u32 host1x_syncpt_read_max(struct host1x_syncpt *sp); |
Thierry Reding | b4a20144 | 2015-01-28 14:29:02 +0100 | [diff] [blame] | 155 | u32 host1x_syncpt_read(struct host1x_syncpt *sp); |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 156 | int host1x_syncpt_incr(struct host1x_syncpt *sp); |
Bryan Wu | 64400c3 | 2014-02-19 14:48:36 -0800 | [diff] [blame] | 157 | u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs); |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 158 | int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout, |
| 159 | u32 *value); |
Thierry Reding | 617dd7c | 2017-08-30 12:48:31 +0200 | [diff] [blame] | 160 | struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client, |
Arto Merilainen | 8736fe8 | 2013-10-14 15:21:52 +0300 | [diff] [blame] | 161 | unsigned long flags); |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 162 | void host1x_syncpt_free(struct host1x_syncpt *sp); |
| 163 | |
Arto Merilainen | f5a954f | 2013-10-14 15:21:53 +0300 | [diff] [blame] | 164 | struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp); |
| 165 | u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base); |
| 166 | |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 167 | /* |
| 168 | * host1x channel |
| 169 | */ |
| 170 | |
| 171 | struct host1x_channel; |
| 172 | struct host1x_job; |
| 173 | |
| 174 | struct host1x_channel *host1x_channel_request(struct device *dev); |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 175 | struct host1x_channel *host1x_channel_get(struct host1x_channel *channel); |
| 176 | void host1x_channel_put(struct host1x_channel *channel); |
| 177 | int host1x_job_submit(struct host1x_job *job); |
| 178 | |
| 179 | /* |
| 180 | * host1x job |
| 181 | */ |
| 182 | |
| 183 | struct host1x_reloc { |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 184 | struct { |
| 185 | struct host1x_bo *bo; |
| 186 | unsigned long offset; |
| 187 | } cmdbuf; |
| 188 | struct { |
| 189 | struct host1x_bo *bo; |
| 190 | unsigned long offset; |
| 191 | } target; |
| 192 | unsigned long shift; |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | struct host1x_job { |
| 196 | /* When refcount goes to zero, job can be freed */ |
| 197 | struct kref ref; |
| 198 | |
| 199 | /* List entry */ |
| 200 | struct list_head list; |
| 201 | |
| 202 | /* Channel where job is submitted to */ |
| 203 | struct host1x_channel *channel; |
| 204 | |
Thierry Reding | bf3d41c | 2018-05-16 14:12:33 +0200 | [diff] [blame] | 205 | /* client where the job originated */ |
| 206 | struct host1x_client *client; |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 207 | |
| 208 | /* Gathers and their memory */ |
| 209 | struct host1x_job_gather *gathers; |
| 210 | unsigned int num_gathers; |
| 211 | |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 212 | /* Array of handles to be pinned & unpinned */ |
Thierry Reding | 06490bb | 2018-05-16 16:58:44 +0200 | [diff] [blame] | 213 | struct host1x_reloc *relocs; |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 214 | unsigned int num_relocs; |
| 215 | struct host1x_job_unpin_data *unpins; |
| 216 | unsigned int num_unpins; |
| 217 | |
| 218 | dma_addr_t *addr_phys; |
| 219 | dma_addr_t *gather_addr_phys; |
| 220 | dma_addr_t *reloc_addr_phys; |
| 221 | |
| 222 | /* Sync point id, number of increments and end related to the submit */ |
| 223 | u32 syncpt_id; |
| 224 | u32 syncpt_incrs; |
| 225 | u32 syncpt_end; |
| 226 | |
| 227 | /* Maximum time to wait for this job */ |
| 228 | unsigned int timeout; |
| 229 | |
| 230 | /* Index and number of slots used in the push buffer */ |
| 231 | unsigned int first_get; |
| 232 | unsigned int num_slots; |
| 233 | |
| 234 | /* Copy of gathers */ |
| 235 | size_t gather_copy_size; |
| 236 | dma_addr_t gather_copy; |
| 237 | u8 *gather_copy_mapped; |
| 238 | |
| 239 | /* Check if register is marked as an address reg */ |
Dmitry Osipenko | a2b78b0 | 2017-06-15 02:18:38 +0300 | [diff] [blame] | 240 | int (*is_addr_reg)(struct device *dev, u32 class, u32 reg); |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 241 | |
Dmitry Osipenko | 0f563a4 | 2017-06-15 02:18:37 +0300 | [diff] [blame] | 242 | /* Check if class belongs to the unit */ |
| 243 | int (*is_valid_class)(u32 class); |
| 244 | |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 245 | /* Request a SETCLASS to this class */ |
| 246 | u32 class; |
| 247 | |
| 248 | /* Add a channel wait for previous ops to complete */ |
| 249 | bool serialize; |
| 250 | }; |
| 251 | |
| 252 | struct host1x_job *host1x_job_alloc(struct host1x_channel *ch, |
Thierry Reding | 24c94e1 | 2018-05-05 08:45:47 +0200 | [diff] [blame] | 253 | u32 num_cmdbufs, u32 num_relocs); |
Thierry Reding | 326bbd7 | 2018-05-16 17:01:43 +0200 | [diff] [blame] | 254 | void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo, |
| 255 | unsigned int words, unsigned int offset); |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 256 | struct host1x_job *host1x_job_get(struct host1x_job *job); |
| 257 | void host1x_job_put(struct host1x_job *job); |
| 258 | int host1x_job_pin(struct host1x_job *job, struct device *dev); |
| 259 | void host1x_job_unpin(struct host1x_job *job); |
| 260 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 261 | /* |
| 262 | * subdevice probe infrastructure |
| 263 | */ |
| 264 | |
| 265 | struct host1x_device; |
| 266 | |
Thierry Reding | 466749f | 2017-04-10 12:27:01 +0200 | [diff] [blame] | 267 | /** |
| 268 | * struct host1x_driver - host1x logical device driver |
| 269 | * @driver: core driver |
| 270 | * @subdevs: table of OF device IDs matching subdevices for this driver |
| 271 | * @list: list node for the driver |
| 272 | * @probe: called when the host1x logical device is probed |
| 273 | * @remove: called when the host1x logical device is removed |
| 274 | * @shutdown: called when the host1x logical device is shut down |
| 275 | */ |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 276 | struct host1x_driver { |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 277 | struct device_driver driver; |
| 278 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 279 | const struct of_device_id *subdevs; |
| 280 | struct list_head list; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 281 | |
| 282 | int (*probe)(struct host1x_device *device); |
| 283 | int (*remove)(struct host1x_device *device); |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 284 | void (*shutdown)(struct host1x_device *device); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 285 | }; |
| 286 | |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 287 | static inline struct host1x_driver * |
| 288 | to_host1x_driver(struct device_driver *driver) |
| 289 | { |
| 290 | return container_of(driver, struct host1x_driver, driver); |
| 291 | } |
| 292 | |
| 293 | int host1x_driver_register_full(struct host1x_driver *driver, |
| 294 | struct module *owner); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 295 | void host1x_driver_unregister(struct host1x_driver *driver); |
| 296 | |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 297 | #define host1x_driver_register(driver) \ |
| 298 | host1x_driver_register_full(driver, THIS_MODULE) |
| 299 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 300 | struct host1x_device { |
| 301 | struct host1x_driver *driver; |
| 302 | struct list_head list; |
| 303 | struct device dev; |
| 304 | |
| 305 | struct mutex subdevs_lock; |
| 306 | struct list_head subdevs; |
| 307 | struct list_head active; |
| 308 | |
| 309 | struct mutex clients_lock; |
| 310 | struct list_head clients; |
Thierry Reding | 536e171 | 2014-11-05 11:43:26 +0100 | [diff] [blame] | 311 | |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 312 | bool registered; |
Thierry Reding | 4d14323 | 2019-06-05 10:46:05 +0200 | [diff] [blame] | 313 | |
| 314 | struct device_dma_parameters dma_parms; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 315 | }; |
| 316 | |
| 317 | static inline struct host1x_device *to_host1x_device(struct device *dev) |
| 318 | { |
| 319 | return container_of(dev, struct host1x_device, dev); |
| 320 | } |
| 321 | |
| 322 | int host1x_device_init(struct host1x_device *device); |
| 323 | int host1x_device_exit(struct host1x_device *device); |
| 324 | |
| 325 | int host1x_client_register(struct host1x_client *client); |
| 326 | int host1x_client_unregister(struct host1x_client *client); |
| 327 | |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 328 | struct tegra_mipi_device; |
| 329 | |
| 330 | struct tegra_mipi_device *tegra_mipi_request(struct device *device); |
| 331 | void tegra_mipi_free(struct tegra_mipi_device *device); |
Thierry Reding | 87904c3 | 2016-08-12 16:00:53 +0200 | [diff] [blame] | 332 | int tegra_mipi_enable(struct tegra_mipi_device *device); |
| 333 | int tegra_mipi_disable(struct tegra_mipi_device *device); |
Thierry Reding | 4de6a2d | 2013-09-02 09:48:53 +0200 | [diff] [blame] | 334 | int tegra_mipi_calibrate(struct tegra_mipi_device *device); |
| 335 | |
Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 336 | #endif |