[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 06/13] hw/block/pflash_cfi02: Add helpers to manipul
From: |
Philippe Mathieu-Daudé |
Subject: |
[Qemu-block] [PATCH 06/13] hw/block/pflash_cfi02: Add helpers to manipulate the status bits |
Date: |
Mon, 6 May 2019 00:15:37 +0200 |
Pull out all of the code to modify the status into simple helper
functions. Status handling becomes more complex once multiple
chips are interleaved to produce a single device.
No change in functionality is intended with this commit.
Signed-off-by: Stephen Checkoway <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Tested-by: Philippe Mathieu-Daudé <address@hidden>
[PMD: Extracted from bigger patch]
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
hw/block/pflash_cfi02.c | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index b27796d74d2..9673eee969f 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -100,6 +100,31 @@ struct PFlashCFI02 {
void *storage;
};
+/*
+ * Toggle status bit DQ7.
+ */
+static inline void toggle_dq7(PFlashCFI02 *pfl)
+{
+ pfl->status ^= 0x80;
+}
+
+/*
+ * Set status bit DQ7 to bit 7 of value.
+ */
+static inline void set_dq7(PFlashCFI02 *pfl, uint8_t value)
+{
+ pfl->status &= 0x7F;
+ pfl->status |= value & 0x80;
+}
+
+/*
+ * Toggle status bit DQ6.
+ */
+static inline void toggle_dq6(PFlashCFI02 *pfl)
+{
+ pfl->status ^= 0x40;
+}
+
/*
* Set up replicated mappings of the same region.
*/
@@ -129,7 +154,7 @@ static void pflash_timer (void *opaque)
trace_pflash_timer_expired(pfl->cmd);
/* Reset flash */
- pfl->status ^= 0x80;
+ toggle_dq7(pfl);
if (pfl->bypass) {
pfl->wcycle = 2;
} else {
@@ -232,7 +257,7 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr offset,
ret = pfl->status;
DPRINTF("%s: status %" PRIx32 "\n", __func__, ret);
/* Toggle bit 6 */
- pfl->status ^= 0x40;
+ toggle_dq6(pfl);
break;
case 0x98:
/* CFI query mode */
@@ -381,7 +406,11 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offset,
break;
}
}
- pfl->status = 0x00 | ~(value & 0x80);
+ /*
+ * While programming, status bit DQ7 should hold the opposite
+ * value from how it was programmed.
+ */
+ set_dq7(pfl, ~value);
/* Let's pretend write is immediate */
if (pfl->bypass)
goto do_bypass;
@@ -429,7 +458,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offset,
memset(pfl->storage, 0xFF, pfl->chip_len);
pflash_update(pfl, 0, pfl->chip_len);
}
- pfl->status = 0x00;
+ set_dq7(pfl, 0x00);
/* Let's wait 5 seconds before chip erase is done */
timer_mod(&pfl->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
(NANOSECONDS_PER_SECOND * 5));
@@ -444,7 +473,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offset,
memset(p + offset, 0xFF, pfl->sector_len);
pflash_update(pfl, offset, pfl->sector_len);
}
- pfl->status = 0x00;
+ set_dq7(pfl, 0x00);
/* Let's wait 1/2 second before sector erase is done */
timer_mod(&pfl->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
(NANOSECONDS_PER_SECOND / 2));
--
2.20.1
- [Qemu-block] [PATCH 10/13] hw/block/pflash_cfi02: Extract the pflash_data_read() function, (continued)
- [Qemu-block] [PATCH 10/13] hw/block/pflash_cfi02: Extract the pflash_data_read() function, Philippe Mathieu-Daudé, 2019/05/05
- [Qemu-block] [PATCH 01/13] tests/pflash-cfi02: Add test for supported CFI commands, Philippe Mathieu-Daudé, 2019/05/05
- [Qemu-block] [PATCH 08/13] hw/block/pflash_cfi02: Use the ldst API in pflash_write(), Philippe Mathieu-Daudé, 2019/05/05
- [Qemu-block] [PATCH 07/13] hw/block/pflash_cfi02: Simplify a statement using fall through, Philippe Mathieu-Daudé, 2019/05/05
- [Qemu-block] [PATCH 11/13] hw/block/pflash_cfi02: Unify the MemoryRegionOps, Philippe Mathieu-Daudé, 2019/05/05
- [Qemu-block] [PATCH 04/13] hw/block/pflash_cfi02: Fix debug format string, Philippe Mathieu-Daudé, 2019/05/05
- [Qemu-block] [PATCH 05/13] hw/block/pflash_cfi02: Add an enum to define the write cycles, Philippe Mathieu-Daudé, 2019/05/05
- [Qemu-block] [PATCH 13/13] hw/block/pflash_cfi02: Use the chip erase time specified in the CFI table, Philippe Mathieu-Daudé, 2019/05/05
- [Qemu-block] [PATCH 12/13] hw/block/pflash_cfi02: Fix command address comparison, Philippe Mathieu-Daudé, 2019/05/05
- [Qemu-block] [PATCH 03/13] tests/pflash-cfi02: Use IEC binary prefixes for size constants, Philippe Mathieu-Daudé, 2019/05/05
- [Qemu-block] [PATCH 06/13] hw/block/pflash_cfi02: Add helpers to manipulate the status bits,
Philippe Mathieu-Daudé <=