From: Giacomo Travaglini Date: Tue, 12 Jan 2021 15:07:02 +0000 (+0000) Subject: dev-arm: Reduce boilerplate when read/writing to Pio devices X-Git-Tag: develop-gem5-snapshot~127 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1ea62dcf80ca4c8e26ab817dbce0fd28c0bf8f20;p=gem5.git dev-arm: Reduce boilerplate when read/writing to Pio devices Change-Id: Id59ac950f37d7f4f2642daf324d501da1ee622de Signed-off-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40775 Reviewed-by: Andreas Sandberg Maintainer: Andreas Sandberg Tested-by: kokoro --- diff --git a/src/dev/arm/pl011.cc b/src/dev/arm/pl011.cc index ea7641615..cfe241ddd 100755 --- a/src/dev/arm/pl011.cc +++ b/src/dev/arm/pl011.cc @@ -64,6 +64,7 @@ Tick Pl011::read(PacketPtr pkt) { assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize); + assert(pkt->getSize() <= 4); Addr daddr = pkt->getAddr() - pioAddr; @@ -145,22 +146,7 @@ Pl011::read(PacketPtr pkt) break; } - switch(pkt->getSize()) { - case 1: - pkt->setLE(data); - break; - case 2: - pkt->setLE(data); - break; - case 4: - pkt->setLE(data); - break; - default: - panic("Uart read size too big?\n"); - break; - } - - + pkt->setUintX(data, ByteOrder::little); pkt->makeAtomicResponse(); return pioDelay; } @@ -170,6 +156,7 @@ Pl011::write(PacketPtr pkt) { assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize); + assert(pkt->getSize() <= 4); Addr daddr = pkt->getAddr() - pioAddr; @@ -179,23 +166,7 @@ Pl011::write(PacketPtr pkt) // use a temporary data since the uart registers are read/written with // different size operations // - uint32_t data = 0; - - switch(pkt->getSize()) { - case 1: - data = pkt->getLE(); - break; - case 2: - data = pkt->getLE(); - break; - case 4: - data = pkt->getLE(); - break; - default: - panic("Uart write size too big?\n"); - break; - } - + const uint32_t data = pkt->getUintX(ByteOrder::little); switch (daddr) { case UART_DR: diff --git a/src/dev/arm/rtc_pl031.cc b/src/dev/arm/rtc_pl031.cc index a6cdc7df6..de84384c1 100644 --- a/src/dev/arm/rtc_pl031.cc +++ b/src/dev/arm/rtc_pl031.cc @@ -61,7 +61,7 @@ Tick PL031::read(PacketPtr pkt) { assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize); - assert(pkt->getSize() == 4); + assert(pkt->getSize() <= 4); Addr daddr = pkt->getAddr() - pioAddr; uint32_t data; @@ -99,22 +99,7 @@ PL031::read(PacketPtr pkt) break; } - switch(pkt->getSize()) { - case 1: - pkt->setLE(data); - break; - case 2: - pkt->setLE(data); - break; - case 4: - pkt->setLE(data); - break; - default: - panic("Uart read size too big?\n"); - break; - } - - + pkt->setUintX(data, ByteOrder::little); pkt->makeAtomicResponse(); return pioDelay; } @@ -123,7 +108,7 @@ Tick PL031::write(PacketPtr pkt) { assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize); - assert(pkt->getSize() == 4); + assert(pkt->getSize() <= 4); Addr daddr = pkt->getAddr() - pioAddr; DPRINTF(Timer, "Writing to RTC at offset: %#x\n", daddr); diff --git a/src/dev/arm/ufs_device.cc b/src/dev/arm/ufs_device.cc index 1406e4afc..e04cb39fa 100644 --- a/src/dev/arm/ufs_device.cc +++ b/src/dev/arm/ufs_device.cc @@ -1029,26 +1029,9 @@ UFSHostDevice::read(PacketPtr pkt) Tick UFSHostDevice::write(PacketPtr pkt) { - uint32_t data = 0; - - switch (pkt->getSize()) { - - case 1: - data = pkt->getLE(); - break; - - case 2: - data = pkt->getLE(); - break; + assert(pkt->getSize() <= 4); - case 4: - data = pkt->getLE(); - break; - - default: - panic("Undefined UFSHCD controller write size!\n"); - break; - } + const uint32_t data = pkt->getUintX(ByteOrder::little); switch (pkt->getAddr() & 0xFF) {