19952f691SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 26579324aSTerje Bergstrom /* 36579324aSTerje Bergstrom * Tegra host1x Command DMA 46579324aSTerje Bergstrom * 56579324aSTerje Bergstrom * Copyright (c) 2010-2013, NVIDIA Corporation. 66579324aSTerje Bergstrom */ 76579324aSTerje Bergstrom 86579324aSTerje Bergstrom #ifndef __HOST1X_CDMA_H 96579324aSTerje Bergstrom #define __HOST1X_CDMA_H 106579324aSTerje Bergstrom 116579324aSTerje Bergstrom #include <linux/sched.h> 120747a672SArnd Bergmann #include <linux/completion.h> 136579324aSTerje Bergstrom #include <linux/list.h> 14*c24973edSMikko Perttunen #include <linux/workqueue.h> 156579324aSTerje Bergstrom 166579324aSTerje Bergstrom struct host1x_syncpt; 176579324aSTerje Bergstrom struct host1x_userctx_timeout; 186579324aSTerje Bergstrom struct host1x_job; 196579324aSTerje Bergstrom 206579324aSTerje Bergstrom /* 216579324aSTerje Bergstrom * cdma 226579324aSTerje Bergstrom * 236579324aSTerje Bergstrom * This is in charge of a host command DMA channel. 246579324aSTerje Bergstrom * Sends ops to a push buffer, and takes responsibility for unpinning 256579324aSTerje Bergstrom * (& possibly freeing) of memory after those ops have completed. 266579324aSTerje Bergstrom * Producer: 276579324aSTerje Bergstrom * begin 286579324aSTerje Bergstrom * push - send ops to the push buffer 296579324aSTerje Bergstrom * end - start command DMA and enqueue handles to be unpinned 306579324aSTerje Bergstrom * Consumer: 316579324aSTerje Bergstrom * update - call to update sync queue and push buffer, unpin memory 326579324aSTerje Bergstrom */ 336579324aSTerje Bergstrom 346579324aSTerje Bergstrom struct push_buffer { 350169b93fSThierry Reding void *mapped; /* mapped pushbuffer memory */ 36404bfb78SMikko Perttunen dma_addr_t dma; /* device address of pushbuffer */ 372f8a6da8SEmil Goode dma_addr_t phys; /* physical address of pushbuffer */ 386579324aSTerje Bergstrom u32 fence; /* index we've written */ 396579324aSTerje Bergstrom u32 pos; /* index to write to */ 40404bfb78SMikko Perttunen u32 size; 41404bfb78SMikko Perttunen u32 alloc_size; 426579324aSTerje Bergstrom }; 436579324aSTerje Bergstrom 446579324aSTerje Bergstrom struct buffer_timeout { 456579324aSTerje Bergstrom struct delayed_work wq; /* work queue */ 466579324aSTerje Bergstrom bool initialized; /* timer one-time setup flag */ 476579324aSTerje Bergstrom struct host1x_syncpt *syncpt; /* buffer completion syncpt */ 486579324aSTerje Bergstrom u32 syncpt_val; /* syncpt value when completed */ 496579324aSTerje Bergstrom ktime_t start_ktime; /* starting time */ 506579324aSTerje Bergstrom /* context timeout information */ 51bf3d41ccSThierry Reding struct host1x_client *client; 526579324aSTerje Bergstrom }; 536579324aSTerje Bergstrom 546579324aSTerje Bergstrom enum cdma_event { 556579324aSTerje Bergstrom CDMA_EVENT_NONE, /* not waiting for any event */ 566579324aSTerje Bergstrom CDMA_EVENT_SYNC_QUEUE_EMPTY, /* wait for empty sync queue */ 576579324aSTerje Bergstrom CDMA_EVENT_PUSH_BUFFER_SPACE /* wait for space in push buffer */ 586579324aSTerje Bergstrom }; 596579324aSTerje Bergstrom 606579324aSTerje Bergstrom struct host1x_cdma { 616579324aSTerje Bergstrom struct mutex lock; /* controls access to shared state */ 620747a672SArnd Bergmann struct completion complete; /* signalled when event occurs */ 630747a672SArnd Bergmann enum cdma_event event; /* event that complete is waiting for */ 646579324aSTerje Bergstrom unsigned int slots_used; /* pb slots used in current submit */ 656579324aSTerje Bergstrom unsigned int slots_free; /* pb slots free in current submit */ 666579324aSTerje Bergstrom unsigned int first_get; /* DMAGET value, where submit begins */ 676579324aSTerje Bergstrom unsigned int last_pos; /* last value written to DMAPUT */ 686579324aSTerje Bergstrom struct push_buffer push_buffer; /* channel's push buffer */ 696579324aSTerje Bergstrom struct list_head sync_queue; /* job queue */ 706579324aSTerje Bergstrom struct buffer_timeout timeout; /* channel's timeout state/wq */ 716579324aSTerje Bergstrom bool running; 726579324aSTerje Bergstrom bool torndown; 73*c24973edSMikko Perttunen struct work_struct update_work; 746579324aSTerje Bergstrom }; 756579324aSTerje Bergstrom 766579324aSTerje Bergstrom #define cdma_to_channel(cdma) container_of(cdma, struct host1x_channel, cdma) 776579324aSTerje Bergstrom #define cdma_to_host1x(cdma) dev_get_drvdata(cdma_to_channel(cdma)->dev->parent) 786579324aSTerje Bergstrom #define pb_to_cdma(pb) container_of(pb, struct host1x_cdma, push_buffer) 796579324aSTerje Bergstrom 806579324aSTerje Bergstrom int host1x_cdma_init(struct host1x_cdma *cdma); 816579324aSTerje Bergstrom int host1x_cdma_deinit(struct host1x_cdma *cdma); 826579324aSTerje Bergstrom int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job); 836579324aSTerje Bergstrom void host1x_cdma_push(struct host1x_cdma *cdma, u32 op1, u32 op2); 845a5fccbdSThierry Reding void host1x_cdma_push_wide(struct host1x_cdma *cdma, u32 op1, u32 op2, 855a5fccbdSThierry Reding u32 op3, u32 op4); 866579324aSTerje Bergstrom void host1x_cdma_end(struct host1x_cdma *cdma, struct host1x_job *job); 876579324aSTerje Bergstrom void host1x_cdma_update(struct host1x_cdma *cdma); 886579324aSTerje Bergstrom void host1x_cdma_peek(struct host1x_cdma *cdma, u32 dmaget, int slot, 896579324aSTerje Bergstrom u32 *out); 906579324aSTerje Bergstrom unsigned int host1x_cdma_wait_locked(struct host1x_cdma *cdma, 916579324aSTerje Bergstrom enum cdma_event event); 926579324aSTerje Bergstrom void host1x_cdma_update_sync_queue(struct host1x_cdma *cdma, 936579324aSTerje Bergstrom struct device *dev); 946579324aSTerje Bergstrom #endif 95