#define GRUB_OHCI_ED_ADDR_MASK 0x7ff
-#define GRUB_OHCI_ED_PHYS2VIRT(o, bulk, x) ( !(x) ? NULL : ( \
- (bulk) ? \
- (grub_ohci_ed_t)((x) - (o)->ed_bulk_addr + (grub_uint32_t)(o)->ed_bulk) \
- : \
- (grub_ohci_ed_t)((x) - (o)->ed_ctrl_addr + (grub_uint32_t)(o)->ed_ctrl) ) )
-
-#define GRUB_OHCI_ED_VIRT2PHYS(o, bulk, x) ( !(x) ? 0 : ( \
- (bulk) ? \
- ((grub_uint32_t)(x) - (grub_uint32_t)(o)->ed_bulk + (o)->ed_bulk_addr) \
- : \
- ((grub_uint32_t)(x) - (grub_uint32_t)(o)->ed_ctrl + (o)->ed_ctrl_addr) ) )
+static inline grub_ohci_ed_t
+grub_ohci_ed_phys2virt (struct grub_ohci *o, int bulk, grub_uint32_t x)
+{
+ if (!x)
+ return NULL;
+ if (bulk)
+ return (grub_ohci_ed_t) (x - o->ed_bulk_addr
+ + (grub_uint8_t *) o->ed_bulk);
+ return (grub_ohci_ed_t) (x - o->ed_ctrl_addr
+ + (grub_uint8_t *) o->ed_ctrl);
+}
-#define GRUB_OHCI_TD_PHYS2VIRT(o, x) ( !(x) ? NULL : \
- (grub_ohci_td_t)((x) - (o)->td_addr + (grub_uint32_t)(o)->td) )
+static grub_uint32_t
+grub_ohci_virt_to_phys (struct grub_ohci *o, int bulk, grub_ohci_ed_t x)
+{
+ if (!x)
+ return 0;
-#define GRUB_OHCI_TD_VIRT2PHYS(o, x) ( !(x) ? 0 : \
- ((grub_uint32_t)(x) - (grub_uint32_t)(o)->td + (o)->td_addr) )
+ if (bulk)
+ return (grub_uint8_t *) x - (grub_uint8_t *) o->ed_bulk + o->ed_bulk_addr;
+ return (grub_uint8_t *) x - (grub_uint8_t *) o->ed_ctrl + o->ed_ctrl_addr;
+}
+
+static inline grub_ohci_td_t
+grub_ohci_td_phys2virt (struct grub_ohci *o, grub_uint32_t x)
+{
+ if (!x)
+ return NULL;
+ return (grub_ohci_td_t) (x - o->td_addr + (grub_uint8_t *) o->td);
+}
+
+static grub_uint32_t
+grub_ohci_td_virt2phys (struct grub_ohci *o, grub_ohci_td_t x)
+{
+ if (!x)
+ return 0;
+ return (grub_uint8_t *)x - (grub_uint8_t *)o->td + o->td_addr;
+}
static grub_uint32_t
{
count = GRUB_OHCI_BULK_EDS;
ed = o->ed_bulk;
- ed_next = GRUB_OHCI_ED_PHYS2VIRT(o, bulk,
+ ed_next = grub_ohci_ed_phys2virt(o, bulk,
grub_le_to_cpu32 (ed->next_ed) );
}
else
{
count = GRUB_OHCI_CTRL_EDS;
ed = o->ed_ctrl;
- ed_next = GRUB_OHCI_ED_PHYS2VIRT(o, bulk,
+ ed_next = grub_ohci_ed_phys2virt(o, bulk,
grub_le_to_cpu32 (ed->next_ed) );
}
if (ed_next && (i < count))
{
ed = ed_next;
- ed_next = GRUB_OHCI_ED_PHYS2VIRT(o, bulk,
+ ed_next = grub_ohci_ed_phys2virt(o, bulk,
grub_le_to_cpu32 (ed->next_ed) );
continue;
}
* of unplugged devices. */
/* We can link new ED to previous ED safely as the new ED should
* still have set skip bit. */
- ed->next_ed = grub_cpu_to_le32 ( GRUB_OHCI_ED_VIRT2PHYS (o,
+ ed->next_ed = grub_cpu_to_le32 ( grub_ohci_virt_to_phys (o,
bulk, &ed[1]));
return &ed[1];
}
/* Unchain first TD from previous TD if it is chained */
if (td->prev_td_phys)
{
- grub_ohci_td_t td_prev_virt = GRUB_OHCI_TD_PHYS2VIRT(o,
+ grub_ohci_td_t td_prev_virt = grub_ohci_td_phys2virt(o,
td->prev_td_phys);
if (td == (grub_ohci_td_t) td_prev_virt->link_td)
return GRUB_USB_ERR_INTERNAL; /* We don't need de-allocate ED */
/* We can set td_head only when ED is not active, i.e.
* when it is newly allocated. */
- ed_virt->td_head = grub_cpu_to_le32 ( GRUB_OHCI_TD_VIRT2PHYS (o,
+ ed_virt->td_head = grub_cpu_to_le32 ( grub_ohci_td_virt2phys (o,
td_head_virt) );
ed_virt->td_tail = ed_virt->td_head;
}
else
- td_head_virt = GRUB_OHCI_TD_PHYS2VIRT ( o, td_head_phys );
+ td_head_virt = grub_ohci_td_phys2virt ( o, td_head_phys );
/* Set TDs */
td_last_phys = td_head_phys; /* initial value to make compiler happy... */
td_current_virt->token |= grub_cpu_to_le32 ( 7 << 21);
/* Remember last used (processed) TD phys. addr. */
- td_last_phys = GRUB_OHCI_TD_VIRT2PHYS (o, td_current_virt);
+ td_last_phys = grub_ohci_td_virt2phys (o, td_current_virt);
/* Allocate next TD */
td_next_virt = grub_ohci_alloc_td (o);
{
if (i) /* if i==0 we have nothing to free... */
grub_ohci_free_tds (o,
- GRUB_OHCI_TD_PHYS2VIRT(o,
+ grub_ohci_td_phys2virt(o,
grub_le_to_cpu32 (td_head_virt->next_td) ) );
/* Reset head TD */
grub_memset ( (void*)td_head_virt, 0,
/* Chain TDs */
td_current_virt->link_td = (grub_uint32_t) td_next_virt;
td_current_virt->next_td = grub_cpu_to_le32 (
- GRUB_OHCI_TD_VIRT2PHYS (o,
+ grub_ohci_td_virt2phys (o,
td_next_virt) );
- td_next_virt->prev_td_phys = GRUB_OHCI_TD_VIRT2PHYS (o,
+ td_next_virt->prev_td_phys = grub_ohci_td_virt2phys (o,
td_current_virt);
td_current_virt = td_next_virt;
}
* setup sequence and we must handle it. */
ed_virt->target = grub_cpu_to_le32 (target | (1 << 14));
/* Set td_tail */
- ed_virt->td_tail = grub_cpu_to_le32 ( GRUB_OHCI_TD_VIRT2PHYS (o,
- td_current_virt) );
+ ed_virt->td_tail
+ = grub_cpu_to_le32 (grub_ohci_td_virt2phys (o, td_current_virt));
/* Now reset skip bit */
ed_virt->target = grub_cpu_to_le32 (target);
/* ed_virt->td_head = grub_cpu_to_le32 (td_head); Must not be changed, it is maintained by OHCI */
/* I hope we can do it as transfer (most probably) finished OK */
}
/* Prepare pointer to last processed TD */
- tderr_virt = GRUB_OHCI_TD_PHYS2VIRT (o, tderr_phys);
+ tderr_virt = grub_ohci_td_phys2virt (o, tderr_phys);
/* Set index of last processed TD */
if (tderr_virt)
transfer->last_trans = tderr_virt->tr_index;
if (o->bad_OHCI) /* In case of bad_OHCI tderr_phys can be wrong */
{
if ( tderr_phys ) /* check if tderr_phys points to TD with error */
- errcode = grub_le_to_cpu32 ( GRUB_OHCI_TD_PHYS2VIRT (o,
+ errcode = grub_le_to_cpu32 ( grub_ohci_td_phys2virt (o,
tderr_phys)->token )
>> 28;
if ( !tderr_phys || !errcode ) /* tderr_phys not valid or points to wrong TD */
{ /* Retired TD with error should be previous TD to ED->td_head */
- tderr_phys = GRUB_OHCI_TD_PHYS2VIRT (o,
+ tderr_phys = grub_ohci_td_phys2virt (o,
grub_le_to_cpu32 ( ed_virt->td_head) & ~0xf )
->prev_td_phys;
}
* tderr_phys can be zero, check it */
else if ( !tderr_phys )
{ /* Retired TD with error should be previous TD to ED->td_head */
- tderr_phys = GRUB_OHCI_TD_PHYS2VIRT (o,
+ tderr_phys = grub_ohci_td_phys2virt (o,
grub_le_to_cpu32 ( ed_virt->td_head) & ~0xf )
->prev_td_phys;
}
/* Prepare pointer to last processed TD and get error code */
- tderr_virt = GRUB_OHCI_TD_PHYS2VIRT (o, tderr_phys);
+ tderr_virt = grub_ohci_td_phys2virt (o, tderr_phys);
/* Set index of last processed TD */
if (tderr_virt)
{
/* Now we must find last processed TD if bad_OHCI == TRUE */
if (o->bad_OHCI)
{ /* Retired TD with error should be previous TD to ED->td_head */
- tderr_phys = GRUB_OHCI_TD_PHYS2VIRT (o,
+ tderr_phys = grub_ohci_td_phys2virt (o,
grub_le_to_cpu32 ( ed_virt->td_head) & ~0xf)
->prev_td_phys;
}
- tderr_virt = GRUB_OHCI_TD_PHYS2VIRT (o, tderr_phys);
+ tderr_virt = grub_ohci_td_phys2virt (o, tderr_phys);
if (tderr_virt)
transfer->last_trans = tderr_virt->tr_index;
else
if (td_current_virt->prev_td_phys)
{
grub_ohci_td_t td_prev_virt
- = GRUB_OHCI_TD_PHYS2VIRT (o, td_current_virt->prev_td_phys);
+ = grub_ohci_td_phys2virt (o, td_current_virt->prev_td_phys);
td_next_virt = (grub_ohci_td_t) td_prev_virt->link_td;
if (td_current_virt == td_next_virt)