• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef CAMERA_QUEUE_H
10 #define CAMERA_QUEUE_H
11 
12 #include <hdf_dlist.h>
13 #include <osal_atomic.h>
14 #include <osal_mutex.h>
15 #include <osal_spinlock.h>
16 #include <camera/camera_product.h>
17 #include "camera_buffer.h"
18 
19 #define MAX_FRAME   32  /* max buffer count per queue */
20 
21 struct BufferQueue {
22     uint32_t ioModes;
23     uint32_t flags;
24     struct BufferQueueOps *queueOps;
25     uint32_t bufferSize;
26     uint32_t minBuffersNeeded;
27     struct OsalMutex mmapLock;
28     uint32_t memType;
29     struct CameraBuffer *buffers[MAX_FRAME];
30     uint32_t numBuffers;
31     struct DListHead queuedList;
32     uint32_t queuedCount;
33     OsalAtomic driverOwnCount;
34     struct DListHead doneList;
35     OsalSpinlock doneLock;
36     wait_queue_head_t doneWait;
37     uint32_t queueIsInit;
38     struct MemOps *memOps;
39 };
40 
41 struct MemOps {
42     void *(*mmapAlloc)(struct BufferQueue *queue, uint32_t planeNum, unsigned long size);
43     void (*mmapFree)(void *bufPriv);
44     void *(*getDmaBuf)(void *bufPriv, uint32_t flags);
45     void *(*allocUserPtr)(struct BufferQueue *queue, uint32_t planeNum, unsigned long vaddr, unsigned long size);
46     void (*freeUserPtr)(void *bufPriv);
47     void (*syncForDevice)(void *bufPriv);
48     void (*syncForUser)(void *bufPriv);
49     void *(*attachDmaBuf)(struct BufferQueue *queue, uint32_t planeNum, void *dmaBuf, unsigned long size);
50     void (*detachDmaBuf)(void *bufPriv);
51     int32_t (*mapDmaBuf)(void *bufPriv);
52     void (*unmapDmaBuf)(void *bufPriv);
53     void *(*getVaddr)(void *bufPriv);
54     void *(*getCookie)(void *bufPriv);
55     uint32_t (*numUsers)(void *bufPriv);
56     int32_t (*mmap)(void *bufPriv, void *vm);
57 };
58 
59 struct BufferQueueOps {
60     int32_t (*queueSetup)(struct BufferQueue *queue, uint32_t *bufferCount, uint32_t *planeCount, uint32_t sizes[]);
61     void (*queueBuffer)(struct BufferQueue *queue, struct CameraBuffer *buffer);
62 };
63 
64 /* BufferQueue flags */
65 enum QueueState {
66     QUEUE_STATE_STREAMING = (1 << 0),               /**< set bit: queue is streaming */
67     QUEUE_STATE_WAITING_DEQUEUE = (1 << 1),         /**< set bit: queue is waiting buffer dequeue */
68     QUEUE_STATE_STREAMING_CALLED = (1 << 2),        /**< set bit: start streaming is called */
69     QUEUE_STATE_ERROR = (1 << 3),                   /**< set bit: error happened */
70     QUEUE_STATE_WAITING_BUFFERS = (1 << 4),         /**< set bit: queue is waiting for buffers */
71     QUEUE_STATE_LAST_BUFFER_DEQUEUED = (1 << 5),    /**< set bit: last buffer has been dequeued */
72     QUEUE_STATE_ALLOW_CACHE_HINTS = (1 << 6),       /**< set bit:  queue allow cache hints*/
73     QUEUE_STATE_BIDIRECTIONAL = (1 << 7),           /**< set bit:  queue is bidirectional*/
74 };
75 
76 void BufferQueueStop(struct BufferQueue *queue);
77 int32_t BufferQueueCheckMemOps(struct BufferQueue *queue, enum CameraMemType memType);
78 int32_t BufferQueueReleaseBuffers(struct BufferQueue *queue, struct UserCameraReq *userRequest);
79 int32_t BufferQueueRequestBuffers(struct BufferQueue *queue, struct UserCameraReq *userRequest,
80     uint32_t numBuffers, uint32_t numPlanes, uint32_t planeSizes[]);
81 int32_t BufferQueueStart(struct BufferQueue *queue);
82 int32_t BufferQueuePrepare(struct BufferQueue *queue, struct UserCameraBuffer *userBuffer);
83 
84 
85 #endif  // CAMERA_QUEUE_H