1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Host Simulator Controller Driver                                    */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_hcd_sim_host.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_hcd_sim_host_entry                              PORTABLE C      */
36 /*                                                           6.1.10       */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function dispatch the HCD function internally to the simulator */
44 /*    controller driver.                                                  */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    hcd                                   Pointer to HCD                */
49 /*    function                              Function for driver to perform*/
50 /*    parameter                             Pointer to parameter(s)       */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Completion Status                                                   */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*  _ux_hcd_sim_host_asynch_queue_process          Process asynch queue   */
59 /*  _ux_hcd_sim_host_asynch_schedule               Schedule async work    */
60 /*  _ux_hcd_sim_host_asynchronous_endpoint_create  Create async endpoint  */
61 /*  _ux_hcd_sim_host_asynchronous_endpoint_destroy Destroy async endpoint */
62 /*  _ux_hcd_sim_host_endpoint_reset                Reset endpoint         */
63 /*  _ux_hcd_sim_host_frame_number_get              Get frame number       */
64 /*  _ux_hcd_sim_host_interrupt_endpoint_create     Create endpoint        */
65 /*  _ux_hcd_sim_host_iso_queue_process             Process iso queue      */
66 /*  _ux_hcd_sim_host_iso_schedule                  Schedule iso work      */
67 /*  _ux_hcd_sim_host_isochronous_endpoint_create   Create iso endpoint    */
68 /*  _ux_hcd_sim_host_periodic_endpoint_destroy     Destroy endpoint       */
69 /*  _ux_hcd_sim_host_periodic_schedule             Schedule periodic      */
70 /*  _ux_hcd_sim_host_port_status_get               Get port status        */
71 /*  _ux_hcd_sim_host_port_reset                    Reset port             */
72 /*  _ux_hcd_sim_host_request_transfer              Request transfer       */
73 /*  _ux_hcd_sim_host_transfer_abort                Abort transfer         */
74 /*                                                                        */
75 /*  CALLED BY                                                             */
76 /*                                                                        */
77 /*    Host Stack                                                          */
78 /*                                                                        */
79 /*  RELEASE HISTORY                                                       */
80 /*                                                                        */
81 /*    DATE              NAME                      DESCRIPTION             */
82 /*                                                                        */
83 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
84 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
85 /*                                            added controller disable,   */
86 /*                                            resulting in version 6.1    */
87 /*  11-09-2020     Chaoqiong Xiao           Modified comment(s),          */
88 /*                                            added HCD uninitialize,     */
89 /*                                            resulting in version 6.1.2  */
90 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
91 /*                                            added standalone support,   */
92 /*                                            resulting in version 6.1.10 */
93 /*                                                                        */
94 /**************************************************************************/
_ux_hcd_sim_host_entry(UX_HCD * hcd,UINT function,VOID * parameter)95 UINT  _ux_hcd_sim_host_entry(UX_HCD *hcd, UINT function, VOID *parameter)
96 {
97 
98 UINT                status = 0;
99 UX_HCD_SIM_HOST     *hcd_sim_host;
100 
101 
102     /* Check the status of the controller.  */
103     if (hcd -> ux_hcd_status == UX_UNUSED)
104     {
105 
106         /* Error trap. */
107         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_CONTROLLER_UNKNOWN);
108 
109         /* If trace is enabled, insert this event into the trace buffer.  */
110         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONTROLLER_UNKNOWN, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
111 
112         return(UX_CONTROLLER_UNKNOWN);
113     }
114 
115     /* Get the pointer to the host simulator HCD.  */
116     hcd_sim_host =  (UX_HCD_SIM_HOST *) hcd -> ux_hcd_controller_hardware;
117 
118     /* look at the function and route it.  */
119     switch(function)
120     {
121 
122     case UX_HCD_UNINITIALIZE:
123         status =  _ux_hcd_sim_host_uninitialize(hcd_sim_host);
124         break;
125 
126 
127     case UX_HCD_DISABLE_CONTROLLER:
128 
129         status =  _ux_hcd_sim_host_controller_disable(hcd_sim_host);
130         break;
131 
132 
133     case UX_HCD_GET_PORT_STATUS:
134 
135         status =  _ux_hcd_sim_host_port_status_get(hcd_sim_host, (ULONG) (ALIGN_TYPE) parameter);
136         break;
137 
138 
139     case UX_HCD_ENABLE_PORT:
140 
141         status =  UX_SUCCESS;
142         break;
143 
144 
145     case UX_HCD_DISABLE_PORT:
146 
147         status =  UX_SUCCESS;
148         break;
149 
150 
151     case UX_HCD_POWER_ON_PORT:
152 
153         status =  UX_SUCCESS;
154         break;
155 
156 
157     case UX_HCD_POWER_DOWN_PORT:
158 
159         status =  UX_SUCCESS;
160         break;
161 
162 
163     case UX_HCD_SUSPEND_PORT:
164 
165         status =  UX_SUCCESS;
166         break;
167 
168 
169     case UX_HCD_RESUME_PORT:
170 
171         status =  UX_SUCCESS;
172         break;
173 
174 
175     case UX_HCD_RESET_PORT:
176 
177         status =  _ux_hcd_sim_host_port_reset(hcd_sim_host, (ULONG) (ALIGN_TYPE) parameter);
178         break;
179 
180 
181     case UX_HCD_GET_FRAME_NUMBER:
182 
183         status =  _ux_hcd_sim_host_frame_number_get(hcd_sim_host, (ULONG *) parameter);
184         break;
185 
186 
187     case UX_HCD_SET_FRAME_NUMBER:
188 
189         status =  UX_SUCCESS;
190         break;
191 
192 
193     case UX_HCD_TRANSFER_REQUEST:
194 
195 #if defined(UX_HOST_STANDALONE)
196         status =  _ux_hcd_sim_host_transfer_run(hcd_sim_host, (UX_TRANSFER *) parameter);
197 #else
198         status =  _ux_hcd_sim_host_request_transfer(hcd_sim_host, (UX_TRANSFER *) parameter);
199 #endif
200         break;
201 
202 
203     case UX_HCD_TRANSFER_ABORT:
204 
205         status =  _ux_hcd_sim_host_transfer_abort(hcd_sim_host, (UX_TRANSFER *) parameter);
206         break;
207 
208 
209     case UX_HCD_CREATE_ENDPOINT:
210 
211         switch ((((UX_ENDPOINT*) parameter) -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE)
212         {
213 
214         case UX_CONTROL_ENDPOINT:
215         case UX_BULK_ENDPOINT:
216 
217             status =  _ux_hcd_sim_host_asynchronous_endpoint_create(hcd_sim_host, (UX_ENDPOINT*) parameter);
218             break;
219 
220 
221         case UX_INTERRUPT_ENDPOINT:
222 
223             status =  _ux_hcd_sim_host_interrupt_endpoint_create(hcd_sim_host, (UX_ENDPOINT*) parameter);
224             break;
225 
226 
227         case UX_ISOCHRONOUS_ENDPOINT:
228 
229             status =  _ux_hcd_sim_host_isochronous_endpoint_create(hcd_sim_host, (UX_ENDPOINT*) parameter);
230             break;
231 
232         }
233         break;
234 
235 
236     case UX_HCD_DESTROY_ENDPOINT:
237 
238         switch ((((UX_ENDPOINT*) parameter) -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE)
239         {
240 
241         case UX_CONTROL_ENDPOINT:
242         case UX_BULK_ENDPOINT:
243 
244             status =  _ux_hcd_sim_host_asynchronous_endpoint_destroy(hcd_sim_host, (UX_ENDPOINT*) parameter);
245             break;
246 
247 
248         case UX_INTERRUPT_ENDPOINT:
249         case UX_ISOCHRONOUS_ENDPOINT:
250 
251             status =  _ux_hcd_sim_host_periodic_endpoint_destroy(hcd_sim_host, (UX_ENDPOINT*) parameter);
252             break;
253 
254         }
255         break;
256 
257 
258     case UX_HCD_RESET_ENDPOINT:
259 
260         status =  _ux_hcd_sim_host_endpoint_reset(hcd_sim_host, (UX_ENDPOINT*) parameter);
261         break;
262 
263 
264     case UX_HCD_PROCESS_DONE_QUEUE:
265 
266         _ux_hcd_sim_host_iso_queue_process(hcd_sim_host);
267         _ux_hcd_sim_host_asynch_queue_process(hcd_sim_host);
268         _ux_hcd_sim_host_iso_schedule(hcd_sim_host);
269         _ux_hcd_sim_host_periodic_schedule(hcd_sim_host);
270         _ux_hcd_sim_host_asynch_schedule(hcd_sim_host);
271         status =  UX_SUCCESS;
272         break;
273 
274 
275     default:
276 
277         /* Error trap. */
278         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_FUNCTION_NOT_SUPPORTED);
279 
280         /* If trace is enabled, insert this event into the trace buffer.  */
281         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
282 
283         /* Unknown request, return an error.  */
284         status =  UX_FUNCTION_NOT_SUPPORTED;
285     }
286 
287     /* Return completion status.  */
288     return(status);
289 }
290 
291