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