Skip to content

Commit

Permalink
rv64 ohci build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ua1arn committed Jul 7, 2024
1 parent ba0b16c commit b143470
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
16 changes: 8 additions & 8 deletions src/common/tusb_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align(uint32_t value, uint32_t a
return value & ((uint32_t) ~(alignment-1));
}

TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align4 (uint32_t value) { return (value & 0xFFFFFFFCUL); }
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align8 (uint32_t value) { return (value & 0xFFFFFFF8UL); }
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align16 (uint32_t value) { return (value & 0xFFFFFFF0UL); }
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align32 (uint32_t value) { return (value & 0xFFFFFFE0UL); }
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align4k (uint32_t value) { return (value & 0xFFFFF000UL); }
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_offset4k(uint32_t value) { return (value & 0xFFFUL); }

TU_ATTR_ALWAYS_INLINE static inline bool tu_is_aligned32(uint32_t value) { return (value & 0x1FUL) == 0; }
TU_ATTR_ALWAYS_INLINE static inline uintptr_t tu_align4 (uintptr_t value) { return (value & 0xFFFFFFFCUL); }
TU_ATTR_ALWAYS_INLINE static inline uintptr_t tu_align8 (uintptr_t value) { return (value & 0xFFFFFFF8UL); }
TU_ATTR_ALWAYS_INLINE static inline uintptr_t tu_align16 (uintptr_t value) { return (value & 0xFFFFFFF0UL); }
TU_ATTR_ALWAYS_INLINE static inline uintptr_t tu_align32 (uintptr_t value) { return (value & 0xFFFFFFE0UL); }
TU_ATTR_ALWAYS_INLINE static inline uintptr_t tu_align4k (uintptr_t value) { return (value & 0xFFFFF000UL); }
TU_ATTR_ALWAYS_INLINE static inline uintptr_t tu_offset4k(uintptr_t value) { return (value & 0xFFFUL); }

TU_ATTR_ALWAYS_INLINE static inline bool tu_is_aligned32(uintptr_t value) { return (value & 0x1FUL) == 0; }
TU_ATTR_ALWAYS_INLINE static inline bool tu_is_aligned64(uint64_t value) { return (value & 0x3FUL) == 0; }

//------------- Mathematics -------------//
Expand Down
12 changes: 6 additions & 6 deletions src/portable/ehci/ehci.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static void init_periodic_list(uint8_t rhport) {
ehci_link_t * const head_8ms = list_get_period_head(rhport, 8); //(ehci_link_t *) &ehci_data.period_head_arr[3];

for (uint32_t i = 0; i < FRAMELIST_SIZE; i++) {
framelist[i].address = (uint32_t) head_1ms;
framelist[i].address = (uintptr_t) head_1ms;
framelist[i].type = EHCI_QTYPE_QHD;
}

Expand Down Expand Up @@ -505,7 +505,7 @@ bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) {

// TODO ISO not supported yet
ehci_qhd_t* qhd = qhd_get_from_addr(dev_addr, ep_addr);
ehci_qtd_t * volatile qtd = qhd->attached_qtd;
ehci_qtd_t * volatile qtd = (ehci_qtd_t * volatile) (uintptr_t) qhd->attached_qtd;
TU_VERIFY(qtd != NULL); // no queued transfer

hcd_dcache_invalidate(qtd, sizeof(ehci_qtd_t));
Expand Down Expand Up @@ -582,7 +582,7 @@ void qhd_xfer_complete_isr(ehci_qhd_t * qhd) {
volatile ehci_qtd_t *qtd_overlay = &qhd->qtd_overlay;

// process non-active (completed) QHD with attached (scheduled) TD
if ( !qtd_overlay->active && qhd->attached_qtd != NULL ) {
if ( !qtd_overlay->active && qhd->attached_qtd != (uintptr_t) NULL ) {
xfer_result_t xfer_result;

if ( qtd_overlay->halted ) {
Expand Down Expand Up @@ -903,19 +903,19 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c

// Attach a TD to queue head
static void qhd_attach_qtd(ehci_qhd_t *qhd, ehci_qtd_t *qtd) {
qhd->attached_qtd = qtd;
qhd->attached_qtd = (uintptr_t) qtd;
qhd->attached_buffer = qtd->buffer[0];

// clean and invalidate cache before physically write
hcd_dcache_clean_invalidate(qtd, sizeof(ehci_qtd_t));

qhd->qtd_overlay.next.address = (uint32_t) qtd;
qhd->qtd_overlay.next.address = (uintptr_t) qtd;
hcd_dcache_clean_invalidate(qhd, sizeof(ehci_qhd_t));
}

// Remove an attached TD from queue head
static void qhd_remove_qtd(ehci_qhd_t *qhd) {
ehci_qtd_t * volatile qtd = qhd->attached_qtd;
ehci_qtd_t * volatile qtd = (ehci_qtd_t * volatile) (uintptr_t) qhd->attached_qtd;

qhd->attached_qtd = NULL;
qhd->attached_buffer = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/portable/ehci/ehci.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ typedef struct TU_ATTR_ALIGNED(32)
// Attached TD management, note usbh will only queue 1 TD per QHD.
// buffer for dcache invalidate since td's buffer is modified by HC and finding initial buffer address is not trivial
uint32_t attached_buffer;
ehci_qtd_t * volatile attached_qtd;
uint32_t attached_qtd;
//ehci_qtd_t * volatile attached_qtd;
} ehci_qhd_t;

TU_VERIFY_STATIC( sizeof(ehci_qhd_t) == 64, "size is not correct" );
Expand Down
32 changes: 16 additions & 16 deletions src/portable/ohci/ohci.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ bool hcd_init(uint8_t rhport)
tu_memclr(&ohci_data, sizeof(ohci_data_t));
for(uint8_t i=0; i<32; i++)
{ // assign all interrupt pointers to period head ed
ohci_data.hcca.interrupt_table[i] = (uint32_t) _phys_addr(&ohci_data.period_head_ed);
ohci_data.hcca.interrupt_table[i] = (uintptr_t) _phys_addr(&ohci_data.period_head_ed);
}

ohci_data.control[0].ed.skip = 1;
Expand Down Expand Up @@ -231,9 +231,9 @@ bool hcd_init(uint8_t rhport)
while( OHCI_REG->command_status_bit.controller_reset ) {} // should not take longer than 10 us

//------------- init ohci registers -------------//
OHCI_REG->control_head_ed = (uint32_t) _phys_addr(&ohci_data.control[0].ed);
OHCI_REG->bulk_head_ed = (uint32_t) _phys_addr(&ohci_data.bulk_head_ed);
OHCI_REG->hcca = (uint32_t) _phys_addr(&ohci_data.hcca);
OHCI_REG->control_head_ed = (uintptr_t) _phys_addr(&ohci_data.control[0].ed);
OHCI_REG->bulk_head_ed = (uintptr_t) _phys_addr(&ohci_data.bulk_head_ed);
OHCI_REG->hcca = (uintptr_t) _phys_addr(&ohci_data.hcca);

OHCI_REG->interrupt_disable = OHCI_REG->interrupt_enable; // disable all interrupts
OHCI_REG->interrupt_status = OHCI_REG->interrupt_status; // clear current set bits
Expand Down Expand Up @@ -408,7 +408,7 @@ static ohci_ed_t * ed_find_free(void)
static void ed_list_insert(ohci_ed_t * p_pre, ohci_ed_t * p_ed)
{
p_ed->next = p_pre->next;
p_pre->next = (uint32_t) _phys_addr(p_ed);
p_pre->next = (uintptr_t) _phys_addr(p_ed);
}

static void ed_list_remove_by_addr(ohci_ed_t * p_head, uint8_t dev_addr)
Expand All @@ -417,7 +417,7 @@ static void ed_list_remove_by_addr(ohci_ed_t * p_head, uint8_t dev_addr)

while( p_prev->next )
{
ohci_ed_t* ed = (ohci_ed_t*) _virt_addr((void *)p_prev->next);
ohci_ed_t* ed = (ohci_ed_t*) _virt_addr((void *)(uintptr_t)p_prev->next);

if (ed->dev_addr == dev_addr)
{
Expand All @@ -428,12 +428,12 @@ static void ed_list_remove_by_addr(ohci_ed_t * p_head, uint8_t dev_addr)
p_prev->next = ed->next;

// point the removed ED's next pointer to list head to make sure HC can always safely move away from this ED
ed->next = (uint32_t) _phys_addr(p_head);
ed->next = (uintptr_t) _phys_addr(p_head);
ed->used = 0;
ed->skip = 0;
}else
{
p_prev = (ohci_ed_t*) _virt_addr((void *)p_prev->next);
p_prev = (ohci_ed_t*) _virt_addr((void *)(uintptr_t)p_prev->next);
}
}
}
Expand All @@ -453,11 +453,11 @@ static void td_insert_to_ed(ohci_ed_t* p_ed, ohci_gtd_t * p_gtd)
// tail is always NULL
if ( tu_align16(p_ed->td_head.address) == 0 )
{ // TD queue is empty --> head = TD
p_ed->td_head.address |= (uint32_t) _phys_addr(p_gtd);
p_ed->td_head.address |= (uintptr_t) _phys_addr(p_gtd);
}
else
{ // TODO currently only support queue up to 2 TD each endpoint at a time
((ohci_gtd_t*) tu_align16((uint32_t)_virt_addr((void *)p_ed->td_head.address)))->next = (uint32_t) _phys_addr(p_gtd);
((ohci_gtd_t*) tu_align16((uintptr_t)_virt_addr((void *)(uintptr_t)p_ed->td_head.address)))->next = (uintptr_t) _phys_addr(p_gtd);
}
ohci_data_clean_invalidate();
}
Expand Down Expand Up @@ -517,7 +517,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
qtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES;

//------------- Attach TDs list to Control Endpoint -------------//
ed->td_head.address = (uint32_t) _phys_addr(qtd);
ed->td_head.address = (uintptr_t) _phys_addr(qtd);

ohci_data_clean_invalidate();
OHCI_REG->command_status_bit.control_list_filled = 1;
Expand Down Expand Up @@ -549,7 +549,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
gtd->data_toggle = GTD_DT_DATA1; // Both Data and Ack stage start with DATA1
gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES;

ed->td_head.address = (uint32_t) _phys_addr(gtd);
ed->td_head.address = (uintptr_t) _phys_addr(gtd);

ohci_data_clean_invalidate();
OHCI_REG->command_status_bit.control_list_filled = 1;
Expand Down Expand Up @@ -610,10 +610,10 @@ static ohci_td_item_t* list_reverse(ohci_td_item_t* td_head)
while(td_head != NULL)
{
td_head = _virt_addr(td_head);
uint32_t next = td_head->next;
uintptr_t next = td_head->next;

// make current's item become reverse's first item
td_head->next = (uint32_t) td_reverse_head;
td_head->next = (uintptr_t) td_reverse_head;
td_reverse_head = _phys_addr(td_head);

td_head = (ohci_td_item_t*) next; // advance to next item
Expand All @@ -624,7 +624,7 @@ static ohci_td_item_t* list_reverse(ohci_td_item_t* td_head)

static inline bool gtd_is_control(ohci_gtd_t const * const p_qtd)
{
return ((uint32_t) p_qtd) < ((uint32_t) ohci_data.gtd_pool); // check ohci_data_t for memory layout
return ((uintptr_t) p_qtd) < ((uintptr_t) ohci_data.gtd_pool); // check ohci_data_t for memory layout
}

static inline ohci_ed_t* gtd_get_ed(ohci_gtd_t const * const p_qtd)
Expand Down Expand Up @@ -699,7 +699,7 @@ static void done_queue_isr(uint8_t hostid)
hcd_event_xfer_complete(ed->dev_addr, tu_edpt_addr(ed->ep_number, dir), xferred_bytes, event, true);
}

td_head = (ohci_td_item_t*) _virt_addr((void *)td_head->next);
td_head = (ohci_td_item_t*) _virt_addr((void *)(uintptr_t)td_head->next);
}
ohci_data_clean_invalidate();
}
Expand Down

0 comments on commit b143470

Please sign in to comment.