1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <lib/sync/completion.h>
8 
9 #include "xhci.h"
10 #include "xhci-transfer.h"
11 
12 typedef struct {
13     xhci_command_context_t context;
14     sync_completion_t completion;
15     // from command completion event TRB
16     uint32_t status;
17     uint32_t control;
18 } xhci_sync_command_t;
19 
20 void xhci_sync_command_init(xhci_sync_command_t* command);
21 
22 // returns condition code
23 int xhci_sync_command_wait(xhci_sync_command_t* command);
24 
xhci_sync_command_slot_id(xhci_sync_command_t * command)25 static inline int xhci_sync_command_slot_id(xhci_sync_command_t* command) {
26     return (command->control & XHCI_MASK(TRB_SLOT_ID_START, TRB_SLOT_ID_BITS)) >> TRB_SLOT_ID_START;
27 }
28 
29 // executes a command with a 1 second timeout
30 zx_status_t xhci_send_command(xhci_t* xhci, uint32_t command, uint64_t ptr, uint32_t control_bits);
31 
32 // Returns the next extended capability, optionally starting from a
33 // specific capability and/or only matching a particular id.
34 //
35 // prev_cap: if non-null, searching begins at the following capability, otherwise
36 //           searching begins at mmio base.
37 // match_cap_id: if non-null, only capabilities with this id will be returned.
38 uint32_t* xhci_get_next_ext_cap(void* mmio, uint32_t* prev_cap, uint32_t* match_cap_id);
39