116216333SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2e1e90644SThierry Reding /*
3e1e90644SThierry Reding * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
4e1e90644SThierry Reding */
5e1e90644SThierry Reding
6e1e90644SThierry Reding #ifndef __LINUX_HOST1X_H
7e1e90644SThierry Reding #define __LINUX_HOST1X_H
8e1e90644SThierry Reding
9776dc384SThierry Reding #include <linux/device.h>
10c6aeaf56SThierry Reding #include <linux/dma-direction.h>
11c24973edSMikko Perttunen #include <linux/dma-fence.h>
121f39b1dfSThierry Reding #include <linux/spinlock.h>
1335d747a8SThierry Reding #include <linux/types.h>
1435d747a8SThierry Reding
15e1e90644SThierry Reding enum host1x_class {
16e1e90644SThierry Reding HOST1X_CLASS_HOST1X = 0x1,
17e1e90644SThierry Reding HOST1X_CLASS_NVJPG1 = 0x7,
18e1e90644SThierry Reding HOST1X_CLASS_NVENC = 0x21,
190ae797a8SArto Merilainen HOST1X_CLASS_NVENC1 = 0x22,
205f60ed0dSThierry Reding HOST1X_CLASS_GR2D = 0x51,
2146f226c9SMikko Perttunen HOST1X_CLASS_GR2D_SB = 0x52,
2246f226c9SMikko Perttunen HOST1X_CLASS_VIC = 0x5D,
23e1e90644SThierry Reding HOST1X_CLASS_GR3D = 0x60,
24e1e90644SThierry Reding HOST1X_CLASS_NVJPG = 0xC0,
25501be6c1SThierry Reding HOST1X_CLASS_NVDEC = 0xF0,
2653fa7f72SThierry Reding HOST1X_CLASS_NVDEC1 = 0xF5,
27aacdf198SThierry Reding HOST1X_CLASS_OFA = 0xF8,
2853fa7f72SThierry Reding };
29501be6c1SThierry Reding
30501be6c1SThierry Reding struct host1x;
31466749f1SThierry Reding struct host1x_client;
321f39b1dfSThierry Reding struct iommu_group;
331f39b1dfSThierry Reding
341f39b1dfSThierry Reding u64 host1x_get_dma_mask(struct host1x *host1x);
353e9c4584SThierry Reding
363e9c4584SThierry Reding /**
373e9c4584SThierry Reding * struct host1x_bo_cache - host1x buffer object cache
383e9c4584SThierry Reding * @mappings: list of mappings
393e9c4584SThierry Reding * @lock: synchronizes accesses to the list of mappings
401f39b1dfSThierry Reding *
411f39b1dfSThierry Reding * Note that entries are not periodically evicted from this cache and instead need to be
421f39b1dfSThierry Reding * explicitly released. This is used primarily for DRM/KMS where the cache's reference is
431f39b1dfSThierry Reding * released when the last reference to a buffer object represented by a mapping in this
441f39b1dfSThierry Reding * cache is dropped.
451f39b1dfSThierry Reding */
461f39b1dfSThierry Reding struct host1x_bo_cache {
471f39b1dfSThierry Reding struct list_head mappings;
481f39b1dfSThierry Reding struct mutex lock;
491f39b1dfSThierry Reding };
501f39b1dfSThierry Reding
host1x_bo_cache_init(struct host1x_bo_cache * cache)511f39b1dfSThierry Reding static inline void host1x_bo_cache_init(struct host1x_bo_cache *cache)
521f39b1dfSThierry Reding {
531f39b1dfSThierry Reding INIT_LIST_HEAD(&cache->mappings);
541f39b1dfSThierry Reding mutex_init(&cache->lock);
551f39b1dfSThierry Reding }
561f39b1dfSThierry Reding
host1x_bo_cache_destroy(struct host1x_bo_cache * cache)571f39b1dfSThierry Reding static inline void host1x_bo_cache_destroy(struct host1x_bo_cache *cache)
581f39b1dfSThierry Reding {
59466749f1SThierry Reding /* XXX warn if not empty? */
60933deb8cSThierry Reding mutex_destroy(&cache->lock);
61466749f1SThierry Reding }
62466749f1SThierry Reding
63933deb8cSThierry Reding /**
64fd67e9c6SThierry Reding * struct host1x_client_ops - host1x client operations
65fd67e9c6SThierry Reding * @early_init: host1x client early initialization code
66466749f1SThierry Reding * @init: host1x client initialization code
6753fa7f72SThierry Reding * @exit: host1x client tear down code
68933deb8cSThierry Reding * @late_exit: host1x client late tear down code
6953fa7f72SThierry Reding * @suspend: host1x client suspend code
7053fa7f72SThierry Reding * @resume: host1x client resume code
71933deb8cSThierry Reding */
72fd67e9c6SThierry Reding struct host1x_client_ops {
73fd67e9c6SThierry Reding int (*early_init)(struct host1x_client *client);
7453fa7f72SThierry Reding int (*init)(struct host1x_client *client);
7553fa7f72SThierry Reding int (*exit)(struct host1x_client *client);
76466749f1SThierry Reding int (*late_exit)(struct host1x_client *client);
77466749f1SThierry Reding int (*suspend)(struct host1x_client *client);
78466749f1SThierry Reding int (*resume)(struct host1x_client *client);
79608f43adSThierry Reding };
80466749f1SThierry Reding
81aacdf198SThierry Reding /**
82466749f1SThierry Reding * struct host1x_client - host1x client structure
83466749f1SThierry Reding * @list: list node for the host1x client
84466749f1SThierry Reding * @host: pointer to struct device representing the host1x controller
85466749f1SThierry Reding * @dev: pointer to struct device backing this host1x client
86466749f1SThierry Reding * @group: IOMMU group that this client is a member of
872fd2bc7fSColton Lewis * @ops: host1x client operations
882fd2bc7fSColton Lewis * @class: host1x class represented by this client
892fd2bc7fSColton Lewis * @channel: host1x channel associated with this client
90fe696ccbSRandy Dunlap * @syncpts: array of syncpoints requested for this client
91466749f1SThierry Reding * @num_syncpts: number of syncpoints requested for this client
9253fa7f72SThierry Reding * @parent: pointer to parent structure
9353fa7f72SThierry Reding * @usecount: reference count for this structure
94608f43adSThierry Reding * @lock: mutex for mutually exclusive concurrency
9553fa7f72SThierry Reding * @cache: host1x buffer object cache
96aacdf198SThierry Reding */
9753fa7f72SThierry Reding struct host1x_client {
9853fa7f72SThierry Reding struct list_head list;
9953fa7f72SThierry Reding struct device *host;
10053fa7f72SThierry Reding struct device *dev;
10153fa7f72SThierry Reding struct iommu_group *group;
10253fa7f72SThierry Reding
10353fa7f72SThierry Reding const struct host1x_client_ops *ops;
10453fa7f72SThierry Reding
105fd67e9c6SThierry Reding enum host1x_class class;
106fd67e9c6SThierry Reding struct host1x_channel *channel;
107fd67e9c6SThierry Reding
108fd67e9c6SThierry Reding struct host1x_syncpt **syncpts;
1091f39b1dfSThierry Reding unsigned int num_syncpts;
1101f39b1dfSThierry Reding
11153fa7f72SThierry Reding struct host1x_client *parent;
11253fa7f72SThierry Reding unsigned int usecount;
11335d747a8SThierry Reding struct mutex lock;
11435d747a8SThierry Reding
11535d747a8SThierry Reding struct host1x_bo_cache cache;
11635d747a8SThierry Reding };
11735d747a8SThierry Reding
11835d747a8SThierry Reding /*
11935d747a8SThierry Reding * host1x buffer objects
120c6aeaf56SThierry Reding */
1211f39b1dfSThierry Reding
122c6aeaf56SThierry Reding struct host1x_bo;
123c6aeaf56SThierry Reding struct sg_table;
1241f39b1dfSThierry Reding
125c6aeaf56SThierry Reding struct host1x_bo_mapping {
126c6aeaf56SThierry Reding struct kref ref;
127c6aeaf56SThierry Reding struct dma_buf_attachment *attach;
128c6aeaf56SThierry Reding enum dma_data_direction direction;
129c6aeaf56SThierry Reding struct list_head list;
130c6aeaf56SThierry Reding struct host1x_bo *bo;
1311f39b1dfSThierry Reding struct sg_table *sgt;
1321f39b1dfSThierry Reding unsigned int chunks;
1331f39b1dfSThierry Reding struct device *dev;
134c6aeaf56SThierry Reding dma_addr_t phys;
135c6aeaf56SThierry Reding size_t size;
1361f39b1dfSThierry Reding
1371f39b1dfSThierry Reding struct host1x_bo_cache *cache;
1381f39b1dfSThierry Reding struct list_head entry;
1391f39b1dfSThierry Reding };
1401f39b1dfSThierry Reding
to_host1x_bo_mapping(struct kref * ref)14135d747a8SThierry Reding static inline struct host1x_bo_mapping *to_host1x_bo_mapping(struct kref *ref)
14235d747a8SThierry Reding {
14335d747a8SThierry Reding return container_of(ref, struct host1x_bo_mapping, ref);
144c6aeaf56SThierry Reding }
145c6aeaf56SThierry Reding
146c6aeaf56SThierry Reding struct host1x_bo_ops {
14735d747a8SThierry Reding struct host1x_bo *(*get)(struct host1x_bo *bo);
14835d747a8SThierry Reding void (*put)(struct host1x_bo *bo);
14935d747a8SThierry Reding struct host1x_bo_mapping *(*pin)(struct device *dev, struct host1x_bo *bo,
15035d747a8SThierry Reding enum dma_data_direction dir);
15135d747a8SThierry Reding void (*unpin)(struct host1x_bo_mapping *map);
15235d747a8SThierry Reding void *(*mmap)(struct host1x_bo *bo);
1531f39b1dfSThierry Reding void (*munmap)(struct host1x_bo *bo, void *addr);
1541f39b1dfSThierry Reding };
15535d747a8SThierry Reding
15635d747a8SThierry Reding struct host1x_bo {
15735d747a8SThierry Reding const struct host1x_bo_ops *ops;
15835d747a8SThierry Reding struct list_head mappings;
15935d747a8SThierry Reding spinlock_t lock;
1601f39b1dfSThierry Reding };
1611f39b1dfSThierry Reding
host1x_bo_init(struct host1x_bo * bo,const struct host1x_bo_ops * ops)16235d747a8SThierry Reding static inline void host1x_bo_init(struct host1x_bo *bo,
16335d747a8SThierry Reding const struct host1x_bo_ops *ops)
16435d747a8SThierry Reding {
16535d747a8SThierry Reding INIT_LIST_HEAD(&bo->mappings);
16635d747a8SThierry Reding spin_lock_init(&bo->lock);
16735d747a8SThierry Reding bo->ops = ops;
16835d747a8SThierry Reding }
16935d747a8SThierry Reding
host1x_bo_get(struct host1x_bo * bo)17035d747a8SThierry Reding static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
17135d747a8SThierry Reding {
17235d747a8SThierry Reding return bo->ops->get(bo);
17335d747a8SThierry Reding }
17435d747a8SThierry Reding
host1x_bo_put(struct host1x_bo * bo)1751f39b1dfSThierry Reding static inline void host1x_bo_put(struct host1x_bo *bo)
1761f39b1dfSThierry Reding {
1771f39b1dfSThierry Reding bo->ops->put(bo);
1781f39b1dfSThierry Reding }
17935d747a8SThierry Reding
18035d747a8SThierry Reding struct host1x_bo_mapping *host1x_bo_pin(struct device *dev, struct host1x_bo *bo,
18135d747a8SThierry Reding enum dma_data_direction dir,
18235d747a8SThierry Reding struct host1x_bo_cache *cache);
18335d747a8SThierry Reding void host1x_bo_unpin(struct host1x_bo_mapping *map);
18435d747a8SThierry Reding
host1x_bo_mmap(struct host1x_bo * bo)18535d747a8SThierry Reding static inline void *host1x_bo_mmap(struct host1x_bo *bo)
18635d747a8SThierry Reding {
18735d747a8SThierry Reding return bo->ops->mmap(bo);
18835d747a8SThierry Reding }
18935d747a8SThierry Reding
host1x_bo_munmap(struct host1x_bo * bo,void * addr)19035d747a8SThierry Reding static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
19135d747a8SThierry Reding {
19235d747a8SThierry Reding bo->ops->munmap(bo, addr);
19335d747a8SThierry Reding }
1948736fe81SArto Merilainen
195f5a954feSArto Merilainen /*
1968736fe81SArto Merilainen * host1x syncpoints
197f5a954feSArto Merilainen */
19835d747a8SThierry Reding
19935d747a8SThierry Reding #define HOST1X_SYNCPT_CLIENT_MANAGED (1 << 0)
20035d747a8SThierry Reding #define HOST1X_SYNCPT_HAS_BASE (1 << 1)
2012aed4f5aSMikko Perttunen
2022aed4f5aSMikko Perttunen struct host1x_syncpt_base;
2032aed4f5aSMikko Perttunen struct host1x_syncpt;
20435d747a8SThierry Reding struct host1x;
20535d747a8SThierry Reding
20635d747a8SThierry Reding struct host1x_syncpt *host1x_syncpt_get_by_id(struct host1x *host, u32 id);
207b4a20144SThierry Reding struct host1x_syncpt *host1x_syncpt_get_by_id_noref(struct host1x *host, u32 id);
20835d747a8SThierry Reding struct host1x_syncpt *host1x_syncpt_get(struct host1x_syncpt *sp);
20964400c37SBryan Wu u32 host1x_syncpt_id(struct host1x_syncpt *sp);
21035d747a8SThierry Reding u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
21135d747a8SThierry Reding u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
212617dd7ccSThierry Reding u32 host1x_syncpt_read(struct host1x_syncpt *sp);
2138736fe81SArto Merilainen int host1x_syncpt_incr(struct host1x_syncpt *sp);
2142aed4f5aSMikko Perttunen u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
21586cec7ecSMikko Perttunen int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
21686cec7ecSMikko Perttunen u32 *value);
21786cec7ecSMikko Perttunen struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
21835d747a8SThierry Reding unsigned long flags);
219f5a954feSArto Merilainen void host1x_syncpt_put(struct host1x_syncpt *sp);
220f5a954feSArto Merilainen struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,
221f5a954feSArto Merilainen unsigned long flags,
222f5ba33fbSMikko Perttunen const char *name);
223f5ba33fbSMikko Perttunen
224f5ba33fbSMikko Perttunen struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
225d5179020SMikko Perttunen u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
226d5179020SMikko Perttunen
227d5179020SMikko Perttunen void host1x_syncpt_release_vblank_reservation(struct host1x_client *client,
228687db220SMikko Perttunen u32 syncpt_id);
22935d747a8SThierry Reding
23035d747a8SThierry Reding struct dma_fence *host1x_fence_create(struct host1x_syncpt *sp, u32 threshold,
23135d747a8SThierry Reding bool timeout);
23235d747a8SThierry Reding void host1x_fence_cancel(struct dma_fence *fence);
23335d747a8SThierry Reding
23435d747a8SThierry Reding /*
23535d747a8SThierry Reding * host1x channel
236caccddcfSThierry Reding */
23735d747a8SThierry Reding
2389ca790f4SDmitry Osipenko struct host1x_channel;
23935d747a8SThierry Reding struct host1x_job;
24035d747a8SThierry Reding
24135d747a8SThierry Reding struct host1x_channel *host1x_channel_request(struct host1x_client *client);
24235d747a8SThierry Reding struct host1x_channel *host1x_channel_get(struct host1x_channel *channel);
24335d747a8SThierry Reding void host1x_channel_stop(struct host1x_channel *channel);
24435d747a8SThierry Reding void host1x_channel_put(struct host1x_channel *channel);
24535d747a8SThierry Reding int host1x_job_submit(struct host1x_job *job);
246ab4f81bfSThierry Reding
247ab4f81bfSThierry Reding /*
248ab4f81bfSThierry Reding * host1x job
24935d747a8SThierry Reding */
250961e3beaSThierry Reding
251961e3beaSThierry Reding #define HOST1X_RELOC_READ (1 << 0)
252961e3beaSThierry Reding #define HOST1X_RELOC_WRITE (1 << 1)
253961e3beaSThierry Reding
254961e3beaSThierry Reding struct host1x_reloc {
255961e3beaSThierry Reding struct {
256961e3beaSThierry Reding struct host1x_bo *bo;
257961e3beaSThierry Reding unsigned long offset;
258961e3beaSThierry Reding } cmdbuf;
259ab4f81bfSThierry Reding struct {
26035d747a8SThierry Reding struct host1x_bo *bo;
26135d747a8SThierry Reding unsigned long offset;
26235d747a8SThierry Reding } target;
26335d747a8SThierry Reding unsigned long shift;
26435d747a8SThierry Reding unsigned long flags;
26535d747a8SThierry Reding };
26635d747a8SThierry Reding
26735d747a8SThierry Reding struct host1x_job {
26835d747a8SThierry Reding /* When refcount goes to zero, job can be freed */
26935d747a8SThierry Reding struct kref ref;
27035d747a8SThierry Reding
27135d747a8SThierry Reding /* List entry */
272bf3d41ccSThierry Reding struct list_head list;
273bf3d41ccSThierry Reding
27435d747a8SThierry Reding /* Channel where job is submitted to */
27535d747a8SThierry Reding struct host1x_channel *channel;
276e902585fSMikko Perttunen
277e902585fSMikko Perttunen /* client where the job originated */
27835d747a8SThierry Reding struct host1x_client *client;
27935d747a8SThierry Reding
28006490bb9SThierry Reding /* Gathers and their memory */
28135d747a8SThierry Reding struct host1x_job_cmd *cmds;
28235d747a8SThierry Reding unsigned int num_cmds;
28335d747a8SThierry Reding
28435d747a8SThierry Reding /* Array of handles to be pinned & unpinned */
28535d747a8SThierry Reding struct host1x_reloc *relocs;
28635d747a8SThierry Reding unsigned int num_relocs;
28735d747a8SThierry Reding struct host1x_job_unpin_data *unpins;
28835d747a8SThierry Reding unsigned int num_unpins;
28935d747a8SThierry Reding
2902aed4f5aSMikko Perttunen dma_addr_t *addr_phys;
29135d747a8SThierry Reding dma_addr_t *gather_addr_phys;
29235d747a8SThierry Reding dma_addr_t *reloc_addr_phys;
29335d747a8SThierry Reding
294c24973edSMikko Perttunen /* Sync point id, number of increments and end related to the submit */
295c24973edSMikko Perttunen struct host1x_syncpt *syncpt;
296c24973edSMikko Perttunen u32 syncpt_incrs;
297c78f837aSMikko Perttunen u32 syncpt_end;
29835d747a8SThierry Reding
29935d747a8SThierry Reding /* Completion fence for job tracking */
30035d747a8SThierry Reding struct dma_fence *fence;
301c78f837aSMikko Perttunen struct dma_fence_cb fence_cb;
302c78f837aSMikko Perttunen
303c78f837aSMikko Perttunen /* Maximum time to wait for this job */
30435d747a8SThierry Reding unsigned int timeout;
30535d747a8SThierry Reding
30635d747a8SThierry Reding /* Job has timed out and should be released */
30735d747a8SThierry Reding bool cancelled;
30835d747a8SThierry Reding
30935d747a8SThierry Reding /* Index and number of slots used in the push buffer */
31035d747a8SThierry Reding unsigned int first_get;
31135d747a8SThierry Reding unsigned int num_slots;
31235d747a8SThierry Reding
31335d747a8SThierry Reding /* Copy of gathers */
314a2b78b0dSDmitry Osipenko size_t gather_copy_size;
31535d747a8SThierry Reding dma_addr_t gather_copy;
3160f563a4bSDmitry Osipenko u8 *gather_copy_mapped;
3170f563a4bSDmitry Osipenko
3180f563a4bSDmitry Osipenko /* Check if register is marked as an address reg */
31935d747a8SThierry Reding int (*is_addr_reg)(struct device *dev, u32 class, u32 reg);
32035d747a8SThierry Reding
32135d747a8SThierry Reding /* Check if class belongs to the unit */
32235d747a8SThierry Reding int (*is_valid_class)(u32 class);
32335d747a8SThierry Reding
324c78f837aSMikko Perttunen /* Request a SETCLASS to this class */
325c78f837aSMikko Perttunen u32 class;
326c78f837aSMikko Perttunen
32717a298e9SMikko Perttunen /* Add a channel wait for previous ops to complete */
32817a298e9SMikko Perttunen bool serialize;
32917a298e9SMikko Perttunen
33017a298e9SMikko Perttunen /* Fast-forward syncpoint increments on job timeout */
3310fddaa85SMikko Perttunen bool syncpt_recovery;
3320fddaa85SMikko Perttunen
3330fddaa85SMikko Perttunen /* Callback called when job is freed */
33424862547SMikko Perttunen void (*release)(struct host1x_job *job);
33524862547SMikko Perttunen void *user_data;
33624862547SMikko Perttunen
33724862547SMikko Perttunen /* Whether host1x-side firewall should be ran for this job or not */
33824862547SMikko Perttunen bool enable_firewall;
33924862547SMikko Perttunen
34024862547SMikko Perttunen /* Options for configuring engine data stream ID */
34124862547SMikko Perttunen /* Context device to use for job */
34235d747a8SThierry Reding struct host1x_memory_context *memory_context;
34335d747a8SThierry Reding /* Stream ID to use if context isolation is disabled (!memory_context) */
34435d747a8SThierry Reding u32 engine_fallback_streamid;
3450fddaa85SMikko Perttunen /* Engine offset to program stream ID to */
3460fddaa85SMikko Perttunen u32 engine_streamid_offset;
347326bbd79SThierry Reding };
348326bbd79SThierry Reding
349e902585fSMikko Perttunen struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
350e902585fSMikko Perttunen u32 num_cmdbufs, u32 num_relocs,
35135d747a8SThierry Reding bool skip_firewall);
35235d747a8SThierry Reding void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
35335d747a8SThierry Reding unsigned int words, unsigned int offset);
35435d747a8SThierry Reding void host1x_job_add_wait(struct host1x_job *job, u32 id, u32 thresh,
35535d747a8SThierry Reding bool relative, u32 next_class);
356776dc384SThierry Reding struct host1x_job *host1x_job_get(struct host1x_job *job);
357776dc384SThierry Reding void host1x_job_put(struct host1x_job *job);
358776dc384SThierry Reding int host1x_job_pin(struct host1x_job *job, struct device *dev);
359776dc384SThierry Reding void host1x_job_unpin(struct host1x_job *job);
360776dc384SThierry Reding
361776dc384SThierry Reding /*
362466749f1SThierry Reding * subdevice probe infrastructure
363466749f1SThierry Reding */
364466749f1SThierry Reding
365466749f1SThierry Reding struct host1x_device;
366466749f1SThierry Reding
367466749f1SThierry Reding /**
368466749f1SThierry Reding * struct host1x_driver - host1x logical device driver
369466749f1SThierry Reding * @driver: core driver
370466749f1SThierry Reding * @subdevs: table of OF device IDs matching subdevices for this driver
371776dc384SThierry Reding * @list: list node for the driver
372f4c5cf88SThierry Reding * @probe: called when the host1x logical device is probed
373f4c5cf88SThierry Reding * @remove: called when the host1x logical device is removed
374776dc384SThierry Reding * @shutdown: called when the host1x logical device is shut down
375776dc384SThierry Reding */
376776dc384SThierry Reding struct host1x_driver {
377776dc384SThierry Reding struct device_driver driver;
378776dc384SThierry Reding
379f4c5cf88SThierry Reding const struct of_device_id *subdevs;
380776dc384SThierry Reding struct list_head list;
381776dc384SThierry Reding
382f4c5cf88SThierry Reding int (*probe)(struct host1x_device *device);
383f4c5cf88SThierry Reding int (*remove)(struct host1x_device *device);
384f4c5cf88SThierry Reding void (*shutdown)(struct host1x_device *device);
385f4c5cf88SThierry Reding };
386f4c5cf88SThierry Reding
387f4c5cf88SThierry Reding static inline struct host1x_driver *
to_host1x_driver(struct device_driver * driver)388f4c5cf88SThierry Reding to_host1x_driver(struct device_driver *driver)
389f4c5cf88SThierry Reding {
390776dc384SThierry Reding return container_of(driver, struct host1x_driver, driver);
391776dc384SThierry Reding }
392f4c5cf88SThierry Reding
393f4c5cf88SThierry Reding int host1x_driver_register_full(struct host1x_driver *driver,
394f4c5cf88SThierry Reding struct module *owner);
395776dc384SThierry Reding void host1x_driver_unregister(struct host1x_driver *driver);
396776dc384SThierry Reding
397776dc384SThierry Reding #define host1x_driver_register(driver) \
398776dc384SThierry Reding host1x_driver_register_full(driver, THIS_MODULE)
399776dc384SThierry Reding
400776dc384SThierry Reding struct host1x_device {
401776dc384SThierry Reding struct host1x_driver *driver;
402776dc384SThierry Reding struct list_head list;
403776dc384SThierry Reding struct device dev;
404776dc384SThierry Reding
405776dc384SThierry Reding struct mutex subdevs_lock;
406536e1715SThierry Reding struct list_head subdevs;
407f4c5cf88SThierry Reding struct list_head active;
4081e390478SThierry Reding
4091e390478SThierry Reding struct mutex clients_lock;
410776dc384SThierry Reding struct list_head clients;
411776dc384SThierry Reding
412776dc384SThierry Reding bool registered;
413776dc384SThierry Reding
414776dc384SThierry Reding struct device_dma_parameters dma_parms;
415776dc384SThierry Reding };
416776dc384SThierry Reding
to_host1x_device(struct device * dev)417776dc384SThierry Reding static inline struct host1x_device *to_host1x_device(struct device *dev)
418776dc384SThierry Reding {
419776dc384SThierry Reding return container_of(dev, struct host1x_device, dev);
4200cfe5a6eSThierry Reding }
4210cfe5a6eSThierry Reding
4220cfe5a6eSThierry Reding int host1x_device_init(struct host1x_device *device);
4230cfe5a6eSThierry Reding int host1x_device_exit(struct host1x_device *device);
424a24f9817SMikko Perttunen
425a24f9817SMikko Perttunen void __host1x_client_init(struct host1x_client *client, struct lock_class_key *key);
4260cfe5a6eSThierry Reding void host1x_client_exit(struct host1x_client *client);
4270cfe5a6eSThierry Reding
4280cfe5a6eSThierry Reding #define host1x_client_init(client) \
4290cfe5a6eSThierry Reding ({ \
4300cfe5a6eSThierry Reding static struct lock_class_key __key; \
4310cfe5a6eSThierry Reding __host1x_client_init(client, &__key); \
4320cfe5a6eSThierry Reding })
4330cfe5a6eSThierry Reding
4340cfe5a6eSThierry Reding int __host1x_client_register(struct host1x_client *client);
4350cfe5a6eSThierry Reding
4360cfe5a6eSThierry Reding /*
4370cfe5a6eSThierry Reding * Note that this wrapper calls __host1x_client_init() for compatibility
4380cfe5a6eSThierry Reding * with existing callers. Callers that want to separately initialize and
4390cfe5a6eSThierry Reding * register a host1x client must first initialize using either of the
4400cfe5a6eSThierry Reding * __host1x_client_init() or host1x_client_init() functions and then use
4410cfe5a6eSThierry Reding * the low-level __host1x_client_register() function to avoid the client
4420cfe5a6eSThierry Reding * getting reinitialized.
4430cfe5a6eSThierry Reding */
444a24f9817SMikko Perttunen #define host1x_client_register(client) \
445a24f9817SMikko Perttunen ({ \
4461d83d1a2SUwe Kleine-König static struct lock_class_key __key; \
447776dc384SThierry Reding __host1x_client_init(client, &__key); \
448fd67e9c6SThierry Reding __host1x_client_register(client); \
449fd67e9c6SThierry Reding })
450fd67e9c6SThierry Reding
4514de6a2d6SThierry Reding void host1x_client_unregister(struct host1x_client *client);
4524de6a2d6SThierry Reding
453767598d4SSowjanya Komatineni int host1x_client_suspend(struct host1x_client *client);
454767598d4SSowjanya Komatineni int host1x_client_resume(struct host1x_client *client);
4554de6a2d6SThierry Reding
45687904c3eSThierry Reding struct tegra_mipi_device;
45787904c3eSThierry Reding
458cf5153e4SSowjanya Komatineni struct tegra_mipi_device *tegra_mipi_request(struct device *device,
459cf5153e4SSowjanya Komatineni struct device_node *np);
4604de6a2d6SThierry Reding void tegra_mipi_free(struct tegra_mipi_device *device);
4618aa5bcb6SMikko Perttunen int tegra_mipi_enable(struct tegra_mipi_device *device);
4628aa5bcb6SMikko Perttunen int tegra_mipi_disable(struct tegra_mipi_device *device);
4638aa5bcb6SMikko Perttunen int tegra_mipi_start_calibration(struct tegra_mipi_device *device);
4648aa5bcb6SMikko Perttunen int tegra_mipi_finish_calibration(struct tegra_mipi_device *device);
4658aa5bcb6SMikko Perttunen
4668aa5bcb6SMikko Perttunen /* host1x memory contexts */
4678aa5bcb6SMikko Perttunen
4688aa5bcb6SMikko Perttunen struct host1x_memory_context {
469*eb0c0621SThierry Reding struct host1x *host;
4708aa5bcb6SMikko Perttunen
4718aa5bcb6SMikko Perttunen refcount_t ref;
4728aa5bcb6SMikko Perttunen struct pid *owner;
4738aa5bcb6SMikko Perttunen
4748aa5bcb6SMikko Perttunen struct device_dma_parameters dma_parms;
4758aa5bcb6SMikko Perttunen struct device dev;
4768aa5bcb6SMikko Perttunen u64 dma_mask;
4778935002fSMikko Perttunen u32 stream_id;
4788aa5bcb6SMikko Perttunen };
4798aa5bcb6SMikko Perttunen
4808aa5bcb6SMikko Perttunen #ifdef CONFIG_IOMMU_API
4818aa5bcb6SMikko Perttunen struct host1x_memory_context *host1x_memory_context_alloc(struct host1x *host1x,
4828aa5bcb6SMikko Perttunen struct device *dev,
4838935002fSMikko Perttunen struct pid *pid);
4848aa5bcb6SMikko Perttunen void host1x_memory_context_get(struct host1x_memory_context *cd);
4858aa5bcb6SMikko Perttunen void host1x_memory_context_put(struct host1x_memory_context *cd);
4868aa5bcb6SMikko Perttunen #else
host1x_memory_context_alloc(struct host1x * host1x,struct device * dev,struct pid * pid)4878aa5bcb6SMikko Perttunen static inline struct host1x_memory_context *host1x_memory_context_alloc(struct host1x *host1x,
4888aa5bcb6SMikko Perttunen struct device *dev,
4898aa5bcb6SMikko Perttunen struct pid *pid)
4908aa5bcb6SMikko Perttunen {
4918aa5bcb6SMikko Perttunen return NULL;
4928aa5bcb6SMikko Perttunen }
4938aa5bcb6SMikko Perttunen
host1x_memory_context_get(struct host1x_memory_context * cd)4948aa5bcb6SMikko Perttunen static inline void host1x_memory_context_get(struct host1x_memory_context *cd)
4958aa5bcb6SMikko Perttunen {
4968aa5bcb6SMikko Perttunen }
4978aa5bcb6SMikko Perttunen
host1x_memory_context_put(struct host1x_memory_context * cd)498e1e90644SThierry Reding static inline void host1x_memory_context_put(struct host1x_memory_context *cd)
499 {
500 }
501 #endif
502
503 #endif
504