Skip to content

Commit e8b3733

Browse files
elbeastoSarah Sharp
authored andcommitted
xhci: replace xhci_read_64() with readq()
Function xhci_read_64() is used to read 64bit xHC registers residing in MMIO. On 32bit systems, xHC registers need to be read with 32bit accesses by reading first the lower 32bits and then the higher 32bits. Replace all calls to xhci_read_64() with calls to readq() and include asm-generic/io-64-nonatomic-lo-hi.h header file, so that if the system is not 64bit, readq() will read registers in 32bit chunks with low-high order. This is done to reduce code duplication since 64bit low-high read logic is already implemented and to take advantage of inherent "atomic" 64bit read operations on 64bit systems. Signed-off-by: Xenia Ragiadakou <[email protected]> Signed-off-by: Sarah Sharp <[email protected]>
1 parent 204b779 commit e8b3733

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

drivers/usb/host/xhci-dbg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num)
203203
addr, (unsigned int)temp);
204204

205205
addr = &ir_set->erst_base;
206-
temp_64 = xhci_read_64(xhci, addr);
206+
temp_64 = readq(addr);
207207
xhci_dbg(xhci, " %p: ir_set.erst_base = @%08llx\n",
208208
addr, temp_64);
209209

210210
addr = &ir_set->erst_dequeue;
211-
temp_64 = xhci_read_64(xhci, addr);
211+
temp_64 = readq(addr);
212212
xhci_dbg(xhci, " %p: ir_set.erst_dequeue = @%08llx\n",
213213
addr, temp_64);
214214
}
@@ -412,7 +412,7 @@ void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci)
412412
{
413413
u64 val;
414414

415-
val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
415+
val = readq(&xhci->op_regs->cmd_ring);
416416
xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = @%08x\n",
417417
lower_32_bits(val));
418418
xhci_dbg(xhci, "// xHC command ring deq ptr high bits = @%08x\n",

drivers/usb/host/xhci-mem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
19581958
xhci_warn(xhci, "WARN something wrong with SW event ring "
19591959
"dequeue ptr.\n");
19601960
/* Update HC event ring dequeue pointer */
1961-
temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
1961+
temp = readq(&xhci->ir_set->erst_dequeue);
19621962
temp &= ERST_PTR_MASK;
19631963
/* Don't clear the EHB bit (which is RW1C) because
19641964
* there might be more events to service.
@@ -2312,7 +2312,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
23122312
(unsigned long long)xhci->cmd_ring->first_seg->dma);
23132313

23142314
/* Set the address in the Command Ring Control register */
2315-
val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
2315+
val_64 = readq(&xhci->op_regs->cmd_ring);
23162316
val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) |
23172317
(xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) |
23182318
xhci->cmd_ring->cycle_state;
@@ -2396,7 +2396,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
23962396
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
23972397
"// Set ERST base address for ir_set 0 = 0x%llx",
23982398
(unsigned long long)xhci->erst.erst_dma_addr);
2399-
val_64 = xhci_read_64(xhci, &xhci->ir_set->erst_base);
2399+
val_64 = readq(&xhci->ir_set->erst_base);
24002400
val_64 &= ERST_PTR_MASK;
24012401
val_64 |= (xhci->erst.erst_dma_addr & (u64) ~ERST_PTR_MASK);
24022402
xhci_write_64(xhci, val_64, &xhci->ir_set->erst_base);

drivers/usb/host/xhci-ring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci)
313313
return 0;
314314
}
315315

316-
temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
316+
temp_64 = readq(&xhci->op_regs->cmd_ring);
317317
if (!(temp_64 & CMD_RING_RUNNING)) {
318318
xhci_dbg(xhci, "Command ring had been stopped\n");
319319
return 0;
@@ -2871,7 +2871,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
28712871
/* Clear the event handler busy flag (RW1C);
28722872
* the event ring should be empty.
28732873
*/
2874-
temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2874+
temp_64 = readq(&xhci->ir_set->erst_dequeue);
28752875
xhci_write_64(xhci, temp_64 | ERST_EHB,
28762876
&xhci->ir_set->erst_dequeue);
28772877
spin_unlock(&xhci->lock);
@@ -2885,7 +2885,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
28852885
*/
28862886
while (xhci_handle_event(xhci) > 0) {}
28872887

2888-
temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2888+
temp_64 = readq(&xhci->ir_set->erst_dequeue);
28892889
/* If necessary, update the HW's version of the event ring deq ptr. */
28902890
if (event_ring_deq != xhci->event_ring->dequeue) {
28912891
deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg,

drivers/usb/host/xhci.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ int xhci_run(struct usb_hcd *hcd)
604604
xhci_dbg(xhci, "Event ring:\n");
605605
xhci_debug_ring(xhci, xhci->event_ring);
606606
xhci_dbg_ring_ptrs(xhci, xhci->event_ring);
607-
temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
607+
temp_64 = readq(&xhci->ir_set->erst_dequeue);
608608
temp_64 &= ~ERST_PTR_MASK;
609609
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
610610
"ERST deq = 64'h%0lx", (long unsigned int) temp_64);
@@ -749,11 +749,11 @@ static void xhci_save_registers(struct xhci_hcd *xhci)
749749
{
750750
xhci->s3.command = readl(&xhci->op_regs->command);
751751
xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification);
752-
xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr);
752+
xhci->s3.dcbaa_ptr = readq(&xhci->op_regs->dcbaa_ptr);
753753
xhci->s3.config_reg = readl(&xhci->op_regs->config_reg);
754754
xhci->s3.erst_size = readl(&xhci->ir_set->erst_size);
755-
xhci->s3.erst_base = xhci_read_64(xhci, &xhci->ir_set->erst_base);
756-
xhci->s3.erst_dequeue = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
755+
xhci->s3.erst_base = readq(&xhci->ir_set->erst_base);
756+
xhci->s3.erst_dequeue = readq(&xhci->ir_set->erst_dequeue);
757757
xhci->s3.irq_pending = readl(&xhci->ir_set->irq_pending);
758758
xhci->s3.irq_control = readl(&xhci->ir_set->irq_control);
759759
}
@@ -776,7 +776,7 @@ static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci)
776776
u64 val_64;
777777

778778
/* step 2: initialize command ring buffer */
779-
val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
779+
val_64 = readq(&xhci->op_regs->cmd_ring);
780780
val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) |
781781
(xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
782782
xhci->cmd_ring->dequeue) &
@@ -3832,7 +3832,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
38323832
if (ret) {
38333833
return ret;
38343834
}
3835-
temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr);
3835+
temp_64 = readq(&xhci->op_regs->dcbaa_ptr);
38363836
xhci_dbg_trace(xhci, trace_xhci_dbg_address,
38373837
"Op regs DCBAA ptr = %#016llx", temp_64);
38383838
xhci_dbg_trace(xhci, trace_xhci_dbg_address,

drivers/usb/host/xhci.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <linux/kernel.h>
2929
#include <linux/usb/hcd.h>
3030

31+
#include <asm-generic/io-64-nonatomic-lo-hi.h>
32+
3133
/* Code sharing between pci-quirks and xhci hcd */
3234
#include "xhci-ext-caps.h"
3335
#include "pci-quirks.h"
@@ -1604,14 +1606,6 @@ static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
16041606
* xHCI implementations that do not support 64-bit address pointers will ignore
16051607
* the high dword, and write order is irrelevant.
16061608
*/
1607-
static inline u64 xhci_read_64(const struct xhci_hcd *xhci,
1608-
__le64 __iomem *regs)
1609-
{
1610-
__u32 __iomem *ptr = (__u32 __iomem *) regs;
1611-
u64 val_lo = readl(ptr);
1612-
u64 val_hi = readl(ptr + 1);
1613-
return val_lo + (val_hi << 32);
1614-
}
16151609
static inline void xhci_write_64(struct xhci_hcd *xhci,
16161610
const u64 val, __le64 __iomem *regs)
16171611
{

0 commit comments

Comments
 (0)