linux/include/linux/host1x.h
<<
>>
Prefs
   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
  12enum 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
  20struct host1x;
  21struct host1x_client;
  22struct iommu_group;
  23
  24u64 host1x_get_dma_mask(struct host1x *host1x);
  25
  26/**
  27 * struct host1x_client_ops - host1x client operations
  28 * @early_init: host1x client early initialization code
  29 * @init: host1x client initialization code
  30 * @exit: host1x client tear down code
  31 * @late_exit: host1x client late tear down code
  32 * @suspend: host1x client suspend code
  33 * @resume: host1x client resume code
  34 */
  35struct host1x_client_ops {
  36        int (*early_init)(struct host1x_client *client);
  37        int (*init)(struct host1x_client *client);
  38        int (*exit)(struct host1x_client *client);
  39        int (*late_exit)(struct host1x_client *client);
  40        int (*suspend)(struct host1x_client *client);
  41        int (*resume)(struct host1x_client *client);
  42};
  43
  44/**
  45 * struct host1x_client - host1x client structure
  46 * @list: list node for the host1x client
  47 * @host: pointer to struct device representing the host1x controller
  48 * @dev: pointer to struct device backing this host1x client
  49 * @group: IOMMU group that this client is a member of
  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 * @parent: pointer to parent structure
  56 * @usecount: reference count for this structure
  57 * @lock: mutex for mutually exclusive concurrency
  58 */
  59struct host1x_client {
  60        struct list_head list;
  61        struct device *host;
  62        struct device *dev;
  63        struct iommu_group *group;
  64
  65        const struct host1x_client_ops *ops;
  66
  67        enum host1x_class class;
  68        struct host1x_channel *channel;
  69
  70        struct host1x_syncpt **syncpts;
  71        unsigned int num_syncpts;
  72
  73        struct host1x_client *parent;
  74        unsigned int usecount;
  75        struct mutex lock;
  76};
  77
  78/*
  79 * host1x buffer objects
  80 */
  81
  82struct host1x_bo;
  83struct sg_table;
  84
  85struct host1x_bo_ops {
  86        struct host1x_bo *(*get)(struct host1x_bo *bo);
  87        void (*put)(struct host1x_bo *bo);
  88        struct sg_table *(*pin)(struct device *dev, struct host1x_bo *bo,
  89                                dma_addr_t *phys);
  90        void (*unpin)(struct device *dev, struct sg_table *sgt);
  91        void *(*mmap)(struct host1x_bo *bo);
  92        void (*munmap)(struct host1x_bo *bo, void *addr);
  93};
  94
  95struct host1x_bo {
  96        const struct host1x_bo_ops *ops;
  97};
  98
  99static inline void host1x_bo_init(struct host1x_bo *bo,
 100                                  const struct host1x_bo_ops *ops)
 101{
 102        bo->ops = ops;
 103}
 104
 105static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
 106{
 107        return bo->ops->get(bo);
 108}
 109
 110static inline void host1x_bo_put(struct host1x_bo *bo)
 111{
 112        bo->ops->put(bo);
 113}
 114
 115static inline struct sg_table *host1x_bo_pin(struct device *dev,
 116                                             struct host1x_bo *bo,
 117                                             dma_addr_t *phys)
 118{
 119        return bo->ops->pin(dev, bo, phys);
 120}
 121
 122static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo,
 123                                   struct sg_table *sgt)
 124{
 125        bo->ops->unpin(dev, sgt);
 126}
 127
 128static inline void *host1x_bo_mmap(struct host1x_bo *bo)
 129{
 130        return bo->ops->mmap(bo);
 131}
 132
 133static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
 134{
 135        bo->ops->munmap(bo, addr);
 136}
 137
 138/*
 139 * host1x syncpoints
 140 */
 141
 142#define HOST1X_SYNCPT_CLIENT_MANAGED    (1 << 0)
 143#define HOST1X_SYNCPT_HAS_BASE          (1 << 1)
 144
 145struct host1x_syncpt_base;
 146struct host1x_syncpt;
 147struct host1x;
 148
 149struct host1x_syncpt *host1x_syncpt_get_by_id(struct host1x *host, u32 id);
 150struct host1x_syncpt *host1x_syncpt_get_by_id_noref(struct host1x *host, u32 id);
 151struct host1x_syncpt *host1x_syncpt_get(struct host1x_syncpt *sp);
 152u32 host1x_syncpt_id(struct host1x_syncpt *sp);
 153u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
 154u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
 155u32 host1x_syncpt_read(struct host1x_syncpt *sp);
 156int host1x_syncpt_incr(struct host1x_syncpt *sp);
 157u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
 158int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
 159                       u32 *value);
 160struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
 161                                            unsigned long flags);
 162void host1x_syncpt_put(struct host1x_syncpt *sp);
 163struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,
 164                                          unsigned long flags,
 165                                          const char *name);
 166
 167struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
 168u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
 169
 170void host1x_syncpt_release_vblank_reservation(struct host1x_client *client,
 171                                              u32 syncpt_id);
 172
 173struct dma_fence *host1x_fence_create(struct host1x_syncpt *sp, u32 threshold);
 174
 175/*
 176 * host1x channel
 177 */
 178
 179struct host1x_channel;
 180struct host1x_job;
 181
 182struct host1x_channel *host1x_channel_request(struct host1x_client *client);
 183struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
 184void host1x_channel_put(struct host1x_channel *channel);
 185int host1x_job_submit(struct host1x_job *job);
 186
 187/*
 188 * host1x job
 189 */
 190
 191#define HOST1X_RELOC_READ       (1 << 0)
 192#define HOST1X_RELOC_WRITE      (1 << 1)
 193
 194struct host1x_reloc {
 195        struct {
 196                struct host1x_bo *bo;
 197                unsigned long offset;
 198        } cmdbuf;
 199        struct {
 200                struct host1x_bo *bo;
 201                unsigned long offset;
 202        } target;
 203        unsigned long shift;
 204        unsigned long flags;
 205};
 206
 207struct host1x_job {
 208        /* When refcount goes to zero, job can be freed */
 209        struct kref ref;
 210
 211        /* List entry */
 212        struct list_head list;
 213
 214        /* Channel where job is submitted to */
 215        struct host1x_channel *channel;
 216
 217        /* client where the job originated */
 218        struct host1x_client *client;
 219
 220        /* Gathers and their memory */
 221        struct host1x_job_cmd *cmds;
 222        unsigned int num_cmds;
 223
 224        /* Array of handles to be pinned & unpinned */
 225        struct host1x_reloc *relocs;
 226        unsigned int num_relocs;
 227        struct host1x_job_unpin_data *unpins;
 228        unsigned int num_unpins;
 229
 230        dma_addr_t *addr_phys;
 231        dma_addr_t *gather_addr_phys;
 232        dma_addr_t *reloc_addr_phys;
 233
 234        /* Sync point id, number of increments and end related to the submit */
 235        struct host1x_syncpt *syncpt;
 236        u32 syncpt_incrs;
 237        u32 syncpt_end;
 238
 239        /* Completion waiter ref */
 240        void *waiter;
 241
 242        /* Maximum time to wait for this job */
 243        unsigned int timeout;
 244
 245        /* Job has timed out and should be released */
 246        bool cancelled;
 247
 248        /* Index and number of slots used in the push buffer */
 249        unsigned int first_get;
 250        unsigned int num_slots;
 251
 252        /* Copy of gathers */
 253        size_t gather_copy_size;
 254        dma_addr_t gather_copy;
 255        u8 *gather_copy_mapped;
 256
 257        /* Check if register is marked as an address reg */
 258        int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
 259
 260        /* Check if class belongs to the unit */
 261        int (*is_valid_class)(u32 class);
 262
 263        /* Request a SETCLASS to this class */
 264        u32 class;
 265
 266        /* Add a channel wait for previous ops to complete */
 267        bool serialize;
 268
 269        /* Fast-forward syncpoint increments on job timeout */
 270        bool syncpt_recovery;
 271
 272        /* Callback called when job is freed */
 273        void (*release)(struct host1x_job *job);
 274        void *user_data;
 275
 276        /* Whether host1x-side firewall should be ran for this job or not */
 277        bool enable_firewall;
 278};
 279
 280struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
 281                                    u32 num_cmdbufs, u32 num_relocs,
 282                                    bool skip_firewall);
 283void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
 284                           unsigned int words, unsigned int offset);
 285void host1x_job_add_wait(struct host1x_job *job, u32 id, u32 thresh,
 286                         bool relative, u32 next_class);
 287struct host1x_job *host1x_job_get(struct host1x_job *job);
 288void host1x_job_put(struct host1x_job *job);
 289int host1x_job_pin(struct host1x_job *job, struct device *dev);
 290void host1x_job_unpin(struct host1x_job *job);
 291
 292/*
 293 * subdevice probe infrastructure
 294 */
 295
 296struct host1x_device;
 297
 298/**
 299 * struct host1x_driver - host1x logical device driver
 300 * @driver: core driver
 301 * @subdevs: table of OF device IDs matching subdevices for this driver
 302 * @list: list node for the driver
 303 * @probe: called when the host1x logical device is probed
 304 * @remove: called when the host1x logical device is removed
 305 * @shutdown: called when the host1x logical device is shut down
 306 */
 307struct host1x_driver {
 308        struct device_driver driver;
 309
 310        const struct of_device_id *subdevs;
 311        struct list_head list;
 312
 313        int (*probe)(struct host1x_device *device);
 314        int (*remove)(struct host1x_device *device);
 315        void (*shutdown)(struct host1x_device *device);
 316};
 317
 318static inline struct host1x_driver *
 319to_host1x_driver(struct device_driver *driver)
 320{
 321        return container_of(driver, struct host1x_driver, driver);
 322}
 323
 324int host1x_driver_register_full(struct host1x_driver *driver,
 325                                struct module *owner);
 326void host1x_driver_unregister(struct host1x_driver *driver);
 327
 328#define host1x_driver_register(driver) \
 329        host1x_driver_register_full(driver, THIS_MODULE)
 330
 331struct host1x_device {
 332        struct host1x_driver *driver;
 333        struct list_head list;
 334        struct device dev;
 335
 336        struct mutex subdevs_lock;
 337        struct list_head subdevs;
 338        struct list_head active;
 339
 340        struct mutex clients_lock;
 341        struct list_head clients;
 342
 343        bool registered;
 344
 345        struct device_dma_parameters dma_parms;
 346};
 347
 348static inline struct host1x_device *to_host1x_device(struct device *dev)
 349{
 350        return container_of(dev, struct host1x_device, dev);
 351}
 352
 353int host1x_device_init(struct host1x_device *device);
 354int host1x_device_exit(struct host1x_device *device);
 355
 356void __host1x_client_init(struct host1x_client *client, struct lock_class_key *key);
 357void host1x_client_exit(struct host1x_client *client);
 358
 359#define host1x_client_init(client)                      \
 360        ({                                              \
 361                static struct lock_class_key __key;     \
 362                __host1x_client_init(client, &__key);   \
 363        })
 364
 365int __host1x_client_register(struct host1x_client *client);
 366
 367/*
 368 * Note that this wrapper calls __host1x_client_init() for compatibility
 369 * with existing callers. Callers that want to separately initialize and
 370 * register a host1x client must first initialize using either of the
 371 * __host1x_client_init() or host1x_client_init() functions and then use
 372 * the low-level __host1x_client_register() function to avoid the client
 373 * getting reinitialized.
 374 */
 375#define host1x_client_register(client)                  \
 376        ({                                              \
 377                static struct lock_class_key __key;     \
 378                __host1x_client_init(client, &__key);   \
 379                __host1x_client_register(client);       \
 380        })
 381
 382int host1x_client_unregister(struct host1x_client *client);
 383
 384int host1x_client_suspend(struct host1x_client *client);
 385int host1x_client_resume(struct host1x_client *client);
 386
 387struct tegra_mipi_device;
 388
 389struct tegra_mipi_device *tegra_mipi_request(struct device *device,
 390                                             struct device_node *np);
 391void tegra_mipi_free(struct tegra_mipi_device *device);
 392int tegra_mipi_enable(struct tegra_mipi_device *device);
 393int tegra_mipi_disable(struct tegra_mipi_device *device);
 394int tegra_mipi_start_calibration(struct tegra_mipi_device *device);
 395int tegra_mipi_finish_calibration(struct tegra_mipi_device *device);
 396
 397#endif
 398