util/fifo8: Introduce fifo8_change_capacity()
cover util/fifo8: Introduce fifo8_change_capacity()
Preliminary series to PL011 FIFO work:
- Clarify doc in qemu_chr_fe_*
- Introduce fifo8_change_capacity()
Philippe Mathieu-Daudé (3):
chardev/char-fe: Document returned value on error util/fifo8: Use fifo8_reset() in fifo8_create() util/fifo8: Introduce fifo8_change_capacity()
include/chardev/char-fe.h | 3 +++ include/qemu/fifo8.h | 10 ++++++++++ util/fifo8.c | 22 ++++++++++++++-------- 3 files changed, 27 insertions(+), 8 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/3 chardev/char-fe: Document returned value on error
qemu_chr_fe_add_watch() and qemu_chr_fe_write[_all]() return -1 on error. Mention it in the documentation.
--- include/chardev/char-fe.h | 3 +++ 1 file changed, 3 insertions(+)
include/chardev/char-fe.h +3 -0
@@ -228,6 +228,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond,* is thread-safe. * * Returns: the number of bytes consumed (0 if no associated Chardev) +* or -1 on error. */ int qemu_chr_fe_write (CharBackend *be,const uint8_t *buf,int len);
@@ -242,6 +243,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len);* attempted to be written. This function is thread-safe. * * Returns: the number of bytes consumed (0 if no associated Chardev) +* or -1 on error. */ int qemu_chr_fe_write_all (CharBackend *be,const uint8_t *buf,int len);
@@ -253,6 +255,7 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len);* Read data to a buffer from the back end. * * Returns: the number of bytes read (0 if no associated Chardev) +* or -1 on error. */ int qemu_chr_fe_read_all (CharBackend *be,uint8_t *buf,int len);
Signature · 1 line
2.41.0
Re: [PATCH 1/3] chardev/char-fe: Document returned value on error
Quoted 29 lines · Philippe Mathieu-Daudé
qemu_chr_fe_add_watch()and qemu_chr_fe_write[_all]() return -1 on error. Mention it in the documentation.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/chardev/char-fe.h | 3 +++ 1 file changed, 3 insertions(+)include/chardev/char-fe.h +2
-0@@ -228,6 +228,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond,* is thread-safe. * * Returns: the number of bytes consumed (0 if no associated Chardev) +* or -1 on error. */ int qemu_chr_fe_write (CharBackend *be,const uint8_t *buf,int len);@@ -242,6 +243,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len);* attempted to be written. This function is thread-safe. * * Returns: the number of bytes consumed (0 if no associated Chardev) +* or -1 on error. */ int qemu_chr_fe_write_all (CharBackend *be,const uint8_t *buf,int len);
include/chardev/char-fe.h int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len); · line 260
Quoted 6 lines
include/chardev/char-fe.h +1
-0@@ -253,6 +255,7 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len);* Read data to a buffer from the back end. * * Returns: the number of bytes read (0 if no associated Chardev) +* or -1 on error. */ int qemu_chr_fe_read_all (CharBackend *be,uint8_t *buf,int len);
ATB,
Mark.
PATCH 2/3 util/fifo8: Use fifo8_reset() in fifo8_create()
In reply to Philippe Mathieu-DaudéAvoid open-coding fifo8_reset() in fifo8_create().
--- util/fifo8.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
util/fifo8.c +7 -8
@@ -16,12 +16,17 @@#include "migration/vmstate.h" #include "qemu/fifo8.h" +void fifo8_reset (Fifo8 *fifo) +{ + fifo->num =0 ; + fifo->head =0 ; +} +void fifo8_create (Fifo8 *fifo,uint32_t capacity) { fifo->data =g_new (uint8_t, capacity); fifo->capacity = capacity; - fifo->head =0 ; - fifo->num =0 ; +fifo8_reset (fifo); }void fifo8_destroy (Fifo8 *fifo)
@@ -97,12 +102,6 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr)return fifo8_peekpop_buf (fifo, max, numptr, true); } -void fifo8_reset (Fifo8 *fifo) -{ - fifo->num =0 ; - fifo->head =0 ; -} -bool fifo8_is_empty (Fifo8 *fifo) {return (fifo->num ==0 );
Signature · 1 line
2.41.0
Re: [PATCH 2/3] util/fifo8: Use fifo8_reset() in fifo8_create()
Quoted 34 lines · Philippe Mathieu-Daudé
Avoid open-coding
fifo8_reset()infifo8_create().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- util/fifo8.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)util/fifo8.c +7
-2@@ -16,12 +16,17 @@#include "migration/vmstate.h" #include "qemu/fifo8.h" +void fifo8_reset (Fifo8 *fifo) +{ + fifo->num =0 ; + fifo->head =0 ; +} +void fifo8_create (Fifo8 *fifo,uint32_t capacity) { fifo->data =g_new (uint8_t, capacity); fifo->capacity = capacity; - fifo->head =0 ; - fifo->num =0 ; +fifo8_reset (fifo); }void fifo8_destroy (Fifo8 *fifo)@@ -97,12 +102,6 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr)return fifo8_peekpop_buf (fifo, max, numptr, true); }
util/fifo8.c const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) · line 107
Quoted 10 lines
util/fifo8.c +0
-6-void fifo8_reset (Fifo8 *fifo) -{ - fifo->num =0 ; - fifo->head =0 ; -} -bool fifo8_is_empty (Fifo8 *fifo) {return (fifo->num ==0 );
ATB,
Mark.
PATCH 3/3 util/fifo8: Introduce fifo8_change_capacity()
In reply to Philippe Mathieu-DaudéFIFOs can be resized at runtime. Introduce thefifo8_change_capacity() method to do that.
When capacity is changed, the FIFO must be reset.
--- include/qemu/fifo8.h | 10 ++++++++++ util/fifo8.c | 7 +++++++ 2 files changed, 17 insertions(+)
include/qemu/fifo8.h +10 -0
@@ -31,6 +31,16 @@ void fifo8_create(Fifo8 *fifo, uint32_t capacity);void fifo8_destroy (Fifo8 *fifo); +/** +* fifo8_change_capacity: +* @fifo: struct Fifo8 to change the capacity +* @capacity: new capacity of the FIFO +* +* Change a FIFO capacity to the specified size. The FIFO is reset. +*/ + +void fifo8_change_capacity (Fifo8 *fifo,uint32_t capacity); +/** * fifo8_push: * @fifo: FIFO to push to
util/fifo8.c +7 -0
@@ -34,6 +34,13 @@ void fifo8_destroy(Fifo8 *fifo)g_free (fifo->data); } +void fifo8_change_capacity (Fifo8 *fifo,uint32_t capacity) +{ + fifo->data =g_renew (uint8_t, fifo->data, capacity); + fifo->capacity = capacity; +fifo8_reset (fifo); +} +void fifo8_push (Fifo8 *fifo,uint8_t data) {assert (fifo->num < fifo->capacity);
Signature · 1 line
2.41.0
Quoted 39 lines · Philippe Mathieu-Daudé
FIFOs can be resized at runtime. Introduce the
fifo8_change_capacity()method to do that.
When capacity is changed, the FIFO must be reset.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/fifo8.h | 10 ++++++++++ util/fifo8.c | 7 +++++++ 2 files changed, 17 insertions(+)include/qemu/fifo8.h +10
-0@@ -31,6 +31,16 @@ void fifo8_create(Fifo8 *fifo, uint32_t capacity);void fifo8_destroy (Fifo8 *fifo); +/** +* fifo8_change_capacity: +* @fifo: struct Fifo8 to change the capacity +* @capacity: new capacity of the FIFO +* +* Change a FIFO capacity to the specified size. The FIFO is reset. +*/ + +void fifo8_change_capacity (Fifo8 *fifo,uint32_t capacity); +/** * fifo8_push: * @fifo: FIFO to push to util/fifo8.c +0
-0@@ -34,6 +34,13 @@ void fifo8_destroy(Fifo8 *fifo)g_free (fifo->data); }
util/fifo8.c void fifo8_destroy(Fifo8 *fifo) · line 46
Quoted 10 lines
util/fifo8.c +7
-0+void fifo8_change_capacity (Fifo8 *fifo,uint32_t capacity) +{ + fifo->data =g_renew (uint8_t, fifo->data, capacity); + fifo->capacity = capacity; +fifo8_reset (fifo); +} +void fifo8_push (Fifo8 *fifo,uint8_t data) {assert (fifo->num < fifo->capacity);
The changes look okay, however I'm a little confused as to why this is needed as generally hardware FIFOs are a fixed size? Presumably this is related to the PL011 series?
ATB,
Mark.
Quoted 42 lines · Mark Cave-Ayland
Quoted 40 lines · Philippe Mathieu-Daudé
FIFOs can be resized at runtime. Introduce the
fifo8_change_capacity()method to do that.
When capacity is changed, the FIFO must be reset.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
include/qemu/fifo8.h| 10 ++++++++++
util/fifo8.c | 7 +++++++2 files changed, 17 insertions(+)include/qemu/fifo8.h +10
-0@@ -31,6 +31,16 @@ void fifo8_create(Fifo8 *fifo, uint32_t capacity); void fifo8_destroy(Fifo8 *fifo); +/** +* fifo8_change_capacity: +* @fifo: struct Fifo8 to change the capacity +* @capacity: new capacity of the FIFO +* +* Change a FIFO capacity to the specified size. The FIFO is reset. +*/ + +void fifo8_change_capacity (Fifo8 *fifo,uint32_t capacity); + /*** fifo8_push: * @fifo: FIFO to push to util/fifo8.c +4
-0@@ -34,6 +34,13 @@ void fifo8_destroy(Fifo8 *fifo) g_free(fifo->data); } +void fifo8_change_capacity (Fifo8 *fifo,uint32_t capacity) +{ + fifo->data = g_renew(uint8_t, fifo->data, capacity); + fifo->capacity = capacity;
Quoted 8 lines
util/fifo8.c void fifo8_destroy(Fifo8 *fifo) · line 46
Quoted 6 lines
util/fifo8.c +3
-0+ fifo8_reset(fifo); +} + void fifo8_push(Fifo8 *fifo, uint8_t data) { assert(fifo->num < fifo->capacity);The changes look okay, however I'm a little confused as to why this is needed as generally hardware FIFOs are a fixed size? Presumably this is related to the PL011 series?
Indeed, this is to model trying to stay as close as possible to the datasheet, which states:
2.4.3 UART operation
Disabling the FIFOs
Additionally, you can disable the FIFOs. In this case, the transmit and receive sides of the UART have 1-byte holding registers (the bottom entry of the FIFOs). The overrun bit is set when a word has been received, and the previous one was not yet read. In this implementation, the FIFOs are not physically disabled, but the flags are manipulated to give the illusion of a 1-byte register.
Quoted 62 lines · Philippe Mathieu-Daudé
Quoted 44 lines · Mark Cave-Ayland
Quoted 42 lines · Philippe Mathieu-Daudé
FIFOs can be resized at runtime. Introduce the
fifo8_change_capacity()method to do that.
When capacity is changed, the FIFO must be reset.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/fifo8.h | 10 ++++++++++ util/fifo8.c | 7 +++++++ 2 files changed, 17 insertions(+)include/qemu/fifo8.h +10
-0@@ -31,6 +31,16 @@ void fifo8_create(Fifo8 *fifo, uint32_t capacity);void fifo8_destroy (Fifo8 *fifo); +/** +* fifo8_change_capacity: +* @fifo: struct Fifo8 to change the capacity +* @capacity: new capacity of the FIFO +* +* Change a FIFO capacity to the specified size. The FIFO is reset. +*/ + +void fifo8_change_capacity (Fifo8 *fifo,uint32_t capacity); +/** * fifo8_push: * @fifo: FIFO to push to util/fifo8.c +6
-0@@ -34,6 +34,13 @@ void fifo8_destroy(Fifo8 *fifo)g_free (fifo->data); } +void fifo8_change_capacity (Fifo8 *fifo,uint32_t capacity) +{ + fifo->data =g_renew (uint8_t, fifo->data, capacity); + fifo->capacity = capacity; +fifo8_reset (fifo); +}Quoted 8 lines
util/fifo8.c void fifo8_destroy(Fifo8 *fifo) · line 46
Quoted 4 lines
util/fifo8.c +1
-0+void fifo8_push (Fifo8 *fifo,uint8_t data) {assert (fifo->num < fifo->capacity);The changes look okay, however I'm a little confused as to why this is needed as generally hardware FIFOs are a fixed size? Presumably this is related to the PL011 series?
Indeed, this is to model trying to stay as close as possible to the datasheet, which states:
2.4.3 UART operation
Disabling the FIFOs
Quoted 7 lines
Additionally, you can disable the FIFOs. In this case, the transmit and receive sides of the UART have 1-byte holding registers (the bottom entry of the FIFOs). The overrun bit is set when a word has been received, and the previous one was not yet read. In this implementation, the FIFOs are not physically disabled, but the flags are manipulated to give the illusion of a 1-byte register.
Notice that in the hardware we don't actually resize the FIFO, though -- we just only ever keep one element in it...
thanks
-- PMM
Quoted 71 lines · Peter Maydell
Quoted 62 lines · Philippe Mathieu-Daudé
Quoted 44 lines · Mark Cave-Ayland
Quoted 42 lines · Philippe Mathieu-Daudé
FIFOs can be resized at runtime. Introduce the
fifo8_change_capacity()method to do that.
When capacity is changed, the FIFO must be reset.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/fifo8.h | 10 ++++++++++ util/fifo8.c | 7 +++++++ 2 files changed, 17 insertions(+)include/qemu/fifo8.h +10
-0@@ -31,6 +31,16 @@ void fifo8_create(Fifo8 *fifo, uint32_t capacity);void fifo8_destroy (Fifo8 *fifo); +/** +* fifo8_change_capacity: +* @fifo: struct Fifo8 to change the capacity +* @capacity: new capacity of the FIFO +* +* Change a FIFO capacity to the specified size. The FIFO is reset. +*/ + +void fifo8_change_capacity (Fifo8 *fifo,uint32_t capacity); +/** * fifo8_push: * @fifo: FIFO to push to util/fifo8.c +6
-0@@ -34,6 +34,13 @@ void fifo8_destroy(Fifo8 *fifo)g_free (fifo->data); } +void fifo8_change_capacity (Fifo8 *fifo,uint32_t capacity) +{ + fifo->data =g_renew (uint8_t, fifo->data, capacity); + fifo->capacity = capacity; +fifo8_reset (fifo); +}Quoted 8 lines
util/fifo8.c void fifo8_destroy(Fifo8 *fifo) · line 46
Quoted 4 lines
util/fifo8.c +1
-0+void fifo8_push (Fifo8 *fifo,uint8_t data) {assert (fifo->num < fifo->capacity);The changes look okay, however I'm a little confused as to why this is needed as generally hardware FIFOs are a fixed size? Presumably this is related to the PL011 series?
Indeed, this is to model trying to stay as close as possible to the datasheet, which states:
2.4.3 UART operation
Disabling the FIFOs
Quoted 7 lines
Additionally, you can disable the FIFOs. In this case, the transmit and receive sides of the UART have 1-byte holding registers (the bottom entry of the FIFOs). The overrun bit is set when a word has been received, and the previous one was not yet read. In this implementation, the FIFOs are not physically disabled, but the flags are manipulated to give the illusion of a 1-byte register.
Quoted 2 lines
Notice that in the hardware we don't actually resize the FIFO, though -- we just only ever keep one element in it...
Yes. IIUC Mark's comment in the PL011 series, we don't need this (confusing) method at all:
https://lore.kernel.org/qemu-devel/[email protected]/