• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef USB_INTERFACE_POOL_H
17 #define USB_INTERFACE_POOL_H
18 
19 #include "usb_session.h"
20 #include "usb_ddk_device.h"
21 #include "usb_ddk_interface.h"
22 #include "usb_ddk_request.h"
23 #include "usb_raw_api_library.h"
24 
25 #define INTERFACE_POOL_ID_MAX   (128)
26 #define INTERFACE_REFCOUNT_UNFORCE  (1)
27 
28 typedef enum {
29     USB_PIPE_INDEX_TYPE,
30     USB_PIPE_DIRECTION_TYPE
31 } UsbPipeQueryParaType;
32 
33 typedef enum {
34     USB_INTERFACE_INTERFACE_INDEX_TYPE,
35     USB_INTERFACE_ALT_SETTINGS_TYPE
36 } UsbInterfaceQueryParaType;
37 
38 typedef enum {
39     USB_POOL_NORMAL_TYPE,
40     USB_POOL_OBJECT_ID_TYPE
41 } UsbPoolQueryParaType;
42 
43 typedef enum {
44     USB_POOL_PROCESS_RUNNING,
45     USB_POOL_PROCESS_STOP,
46     USB_POOL_PROCESS_STOPED
47 } UsbPoolProcessStatusType;
48 
49 struct UsbInterfaceHandleEntity {
50     struct UsbDeviceHandle *devHandle;
51     uint8_t interfaceIndex;
52 };
53 struct UsbSdkInterface {
54     struct UsbInterface interface;
55     int32_t parentObjectId;
56     struct DListHead pipeList;
57     struct OsalMutex listLock;
58     UsbInterfaceStatus status;
59     uint8_t altSettingId;
60     struct UsbSession *session;
61     OsalAtomic refCount;
62 };
63 
64 struct UsbInterfacePool {
65     struct UsbObject object;
66     struct UsbSession *session;
67     struct OsalMutex mutex;
68     struct DListHead interfaceList;
69     struct OsalMutex interfaceLock;
70     OsalAtomic refCount;
71     uint8_t busNum;
72     uint8_t devAddr;
73     OsalAtomic ioRefCount;
74     struct OsalThread ioSendProcess;
75     struct OsalThread ioAsyncReceiveProcess;
76     struct UsbMessageQueue submitRequestQueue;
77     UsbRawTidType ioProcessTid;
78     UsbPoolProcessStatusType ioProcessStopStatus;
79     struct OsalMutex ioStopLock;
80     struct UsbDevice *device;
81 };
82 
83 struct UsbPipeQueryPara {
84     UsbPipeQueryParaType type;
85     union {
86         uint8_t pipeId;
87         UsbPipeDirection pipeDirection;
88     };
89 };
90 
91 struct UsbInterfaceQueryPara {
92     UsbInterfaceQueryParaType type;
93     uint8_t interfaceIndex;
94     uint8_t altSettingId;
95 };
96 
97 struct UsbPoolQueryPara {
98     UsbPoolQueryParaType type;
99     union {
100         struct {
101             uint8_t busNum;
102             uint8_t usbAddr;
103         };
104         int32_t objectId;
105     };
106 };
107 
108 struct UsbIfRequest {
109     struct UsbRequest request;
110     struct UsbHostRequest *hostRequest;
111     bool isSyncReq;
112 }__attribute__((aligned(4)));
113 
114 int32_t UsbIfCreatPipeObj(const struct UsbSdkInterface *interfaceObj, struct UsbPipe **pipeObj);
115 int32_t UsbIfCreatInterfaceObj(const struct UsbInterfacePool *interfacePool, struct UsbSdkInterface **interfaceObj);
116 HDF_STATUS UsbIfDestroyInterfaceObj(
117     const struct UsbInterfacePool *interfacePool, const struct UsbSdkInterface *interfaceObj);
118 int32_t UsbIfCreatInterfacePool(const struct UsbSession *session, uint8_t busNum, uint8_t devAddr,
119     struct UsbInterfacePool **interfacePool);
120 
121 #endif /* USB_INTERFACE_POOL_H */
122