update dcbaa functions in xhci.c, and Makefile in xhci

This commit is contained in:
xj 2024-07-03 04:58:05 -07:00
parent aedc9d86fc
commit 57ae614071
4 changed files with 41 additions and 21 deletions

View File

@ -1,6 +1,6 @@
include $(KERNEL_ROOT)/services/drivers/usb/components/usb.mk
objs += usb_hc_xhci.o
objs += usb_hc_xhci.o xhci.o
all: ${objs}
@echo "generate $^"
@ -8,4 +8,4 @@ all: ${objs}
%.o: %.c
@echo "cc $^"
@${cc} ${cflags} ${c_useropts} ${INC_DIR} -o $@ -c $^
@${cc} ${cflags} ${c_useropts} ${INC_DIR} -o $@ -c $^

View File

@ -673,8 +673,7 @@ err_reset:
*/
static int xhci_dcbaa_alloc ( struct xhci_host *xhci ) {
size_t len;
uintptr_t dcbaap;
uint64_t dcbaap_phy;
uintptr_t dcbaap_addr, dcbaap_phy;
int rc;
/* Allocate and initialise structure. Must be at least
@ -683,21 +682,35 @@ static int xhci_dcbaa_alloc ( struct xhci_host *xhci ) {
* with a minimum of 64 bytes).
*/
len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
xhci->dcbaa.context = usb_align(xhci_align ( len ), len);
// xhci->dcbaa.context = usb_align(xhci_align ( len ), len);
//
xhci->dcbaa.context = NULL;
rc = sys_mmap(&dcbaap_addr, &dcbaap_phy, len);
if(rc != 0){
USB_LOG_ERR("XHCI %s could not allocate DCBAA\n", xhci->name );
rc = -ENOMEM;
goto err_alloc;
}
xhci->dcbaa_addr = dcbaap_addr;
#if 0
if ( ! xhci->dcbaa.context ) {
USB_LOG_ERR("XHCI %s could not allocate DCBAA\n", xhci->name );
rc = -ENOMEM;
goto err_alloc;
}
#endif
memset ( xhci->dcbaa.context, 0, len );
/* Program DCBAA pointer */
dcbaap = (uintptr_t)( xhci->dcbaa.context );
if ( ( rc = xhci_writeq ( xhci, dcbaap,
xhci->op + XHCI_OP_DCBAAP ) ) != 0 )
// dcbaap = (uintptr_t)( xhci->dcbaa.context );
if ( ( rc = xhci_writeq ( xhci, dcbaap_phy,
xhci->op_addr + XHCI_OP_DCBAAP ) ) != 0 )
goto err_writeq;
USB_LOG_DBG("XHCI %s DCBAA at [%08lx,%08lx)\n", xhci->name,
@ -1440,8 +1453,8 @@ int xhci_event_wait(struct xhci_host *xhci,
* @v value Value send to doorbell
*/
static inline void xhci_doorbell ( struct xhci_host *xhci, uint32_t slotid, uint32_t value ) {
DSB();
// DSB();
BARRIER();
writel ( value, xhci->db + slotid * XHCI_REG_DB_SIZE ); /* bit[7:0] db target, is ep_id */
}
@ -1493,7 +1506,8 @@ static int xhci_cmd_submit(struct xhci_host *xhci, struct xhci_endpoint *ep, uni
xhci_trb_queue(xhci->cmds, trb);
/* pass command trb to hardware */
DSB();
// DSB();
BARRIER();
xhci_doorbell(xhci, 0, 0); /* 0 = db host controller, 0 = db targe hc command */
int cc = xhci_event_wait(xhci, ep, xhci->cmds);
@ -2079,8 +2093,8 @@ static inline int xhci_configure_endpoint ( struct xhci_host *xhci,
* @v input Input context
*/
static void
xhci_deconfigure_endpoint_input ( struct xhci_host *xhci __unused,
struct xhci_slot *slot __unused,
xhci_deconfigure_endpoint_input ( struct xhci_host *xhci,
struct xhci_slot *slot,
struct xhci_endpoint *endpoint,
void *input ) {
struct xhci_control_context *control_ctx;
@ -2319,7 +2333,8 @@ void xhci_endpoint_message ( struct xhci_endpoint *ep,
xhci_trb_queue(&(ep->reqs), &trb);
/* pass command trb to hardware */
DSB();
// DSB();
BARRIER();
USB_LOG_DBG("ring doorbell slot-%d ep-%d \r\n", slot->id, ep->ctx);
xhci_doorbell(xhci, slot->id, ep->ctx); /* 0 = db host controller, 0 = db targe hc command */
@ -2367,7 +2382,8 @@ void xhci_endpoint_stream ( struct xhci_endpoint *ep,
xhci_trb_queue(&(ep->reqs), trb);
/* pass command trb to hardware */
DSB();
// DSB();
BARRIER();
xhci_doorbell(xhci, slot->id, ep->ctx);
@ -2386,7 +2402,7 @@ err_enqueue:
* @v input Input context
*/
static void xhci_evaluate_context_input ( struct xhci_host *xhci,
struct xhci_slot *slot __unused,
struct xhci_slot *slot,
struct xhci_endpoint *endpoint,
void *input ) {
struct xhci_control_context *control_ctx;
@ -2625,7 +2641,9 @@ void xhci_event_process(struct xhci_host *xhci) {
/* check and ack event */
for (;;) {
/* Stop if we reach an empty TRB */
DSB();
// DSB();
// __asm__ __volatile__("dsb sy": : : "memory");
BARRIER();
nidx = evts->nidx; /* index of dequeue trb */
cs = evts->cs; /* cycle state toggle by xHc */

View File

@ -864,7 +864,7 @@ struct xhci_host {
*
* dcbaa_addr holds the virtual address of the dcbaa, meanwhile acbaa keeps the value that should be writen to XHCI_OP_DCBAAP.
*/
void *dcbaa_addr;
uintptr_t dcbaa_addr;
struct xhci_dcbaa dcbaa;
/** Scratchpad buffer */

View File

@ -391,9 +391,11 @@ enum {
#define BARRIER() __asm__ __volatile__("": : :"memory")
#ifdef XHCI_AARCH64
#define DSB() __asm__ __volatile__("dsb sy": : : "memory")
// #define DSB() __asm__ __volatile__("dsb sy": : : "memory")
#define DSB() __asm__ volatile("dsb ish\n\t")
#else
#define DSB() __asm__ __volatile__("dsb": : : "memory")
// #define DSB() __asm__ __volatile__("dsb": : : "memory")
#define DSB() __asm__ volatile("dsb ish\n\t")
#endif