nios2: Add Altera JTAG UART emulation
v3 cover nios2: Add Altera JTAG UART emulation
v3: including a link to HW registers specs
Juro Bystricky (1):
nios2: Add Altera JTAG UART emulation
default-configs/nios2-softmmu.mak | 1 + hw/char/Makefile.objs | 1 + hw/char/altera_juart.c | 268 ++++++++++++++++++++++++++++++++++++++ include/hw/char/altera_juart.h | 44 +++++++ 4 files changed, 314 insertions(+) create mode 100644 hw/char/altera_juart.c create mode 100644 include/hw/char/altera_juart.h
Signature · 1 line
2.7.4
PATCH v3 1/1 nios2: Add Altera JTAG UART emulation
Hardware emulation based on:
https://www.altera.com/en_US/pdfs/literature/ug/ug_embedded_ip.pdf
--- default-configs/nios2-softmmu.mak | 1 + hw/char/Makefile.objs | 1 + hw/char/altera_juart.c | 268 ++++++++++++++++++++++++++++++++++++++ include/hw/char/altera_juart.h | 44 +++++++ 4 files changed, 314 insertions(+) create mode 100644 hw/char/altera_juart.c create mode 100644 include/hw/char/altera_juart.h
default-configs/nios2-softmmu.mak +1 -0
@@ -4,3 +4,4 @@ CONFIG_NIOS2=y CONFIG_SERIAL=y CONFIG_PTIMER=y CONFIG_ALTERA_TIMER=y +CONFIG_ALTERA_JUART=y
hw/char/Makefile.objs +1 -0
@@ -27,5 +27,6 @@ common-obj-$(CONFIG_LM32) += lm32_juart.o common-obj-$(CONFIG_LM32) += lm32_uart.o common-obj-$(CONFIG_MILKYMIST) += milkymist-uart.o common-obj-$(CONFIG_SCLPCONSOLE) += sclpconsole.o sclpconsole-lm.o +common-obj-$(CONFIG_ALTERA_JUART) += altera_juart.o obj-$(CONFIG_VIRTIO) += virtio-serial-bus.o
hw/char/altera_juart.c new file +268 -0
268 lines not on this page · raw message
include/hw/char/altera_juart.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 2 lines · Juro Bystricky
Hardware emulation based on:
https://www.altera.com/en_US/pdfs/literature/ug/ug_embedded_ip.pdf
Please make the commit message a bit more verbose, looking just at the commit message, I have no clue what patch I'm looking at. The embedded IP UG also has like 30 cores in it, so some detail on which core and in which chapter/page would help.
Quoted 38 lines
Signed-off-by Juro Bystricky <[email protected]>--- default-configs/nios2-softmmu.mak | 1 + hw/char/Makefile.objs | 1 + hw/char/altera_juart.c | 268 ++++++++++++++++++++++++++++++++++++++ include/hw/char/altera_juart.h | 44 +++++++ 4 files changed, 314 insertions(+) create mode 100644 hw/char/altera_juart.c create mode 100644 include/hw/char/altera_juart.hdefault-configs/nios2-softmmu.mak +1
-0@@ -4,3 +4,4 @@ CONFIG_NIOS2=y CONFIG_SERIAL=y CONFIG_PTIMER=y CONFIG_ALTERA_TIMER=y +CONFIG_ALTERA_JUART=yhw/char/Makefile.objs +1
-0@@ -27,5 +27,6 @@ common-obj-$(CONFIG_LM32) += lm32_juart.o common-obj-$(CONFIG_LM32) += lm32_uart.o common-obj-$(CONFIG_MILKYMIST) += milkymist-uart.o common-obj-$(CONFIG_SCLPCONSOLE) += sclpconsole.o sclpconsole-lm.o +common-obj-$(CONFIG_ALTERA_JUART) += altera_juart.o obj-$(CONFIG_VIRTIO) += virtio-serial-bus.ohw/char/altera_juart.c new file +2
-0@@ -0,0 +1,268 @@ +/* +* QEMU model of the Altera JTAG UART.
hw/char/altera_juart.c line 12
Quoted 10 lines
hw/char/altera_juart.c new file +10
-0+* +* Copyright (c) 2016-2017 Intel Corporation. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>.
Isn't QEMU GPLv2 only and NOT GPLv2+ ?
hw/char/altera_juart.c line 16
Quoted 3 lines
hw/char/altera_juart.c new file +3
-0+* The Altera JTAG UART hardware registers are described in: +* https://www.altera.com/en_US/pdfs/literature/ug/ug_embedded_ip.pdf +*
Drop the trailing newline
Quoted 37 lines
hw/char/altera_juart.c new file +37
-0+*/ + +#include "qemu/osdep.h" +#include "hw/char/altera_juart.h" +#include "sysemu/sysemu.h" +#include "qemu/error-report.h" + +/* Data register */ +#define R_DATA 0 +#define DATA_RVALID BIT(15) +#define DATA_RAVAIL 0xFFFF0000 + +/* Control register */ +#define R_CONTROL 1 +#define CONTROL_RE BIT(0) +#define CONTROL_WE BIT(1) +#define CONTROL_RI BIT(8) +#define CONTROL_WI BIT(9) +#define CONTROL_AC BIT(10) +#define CONTROL_WSPACE 0xFFFF0000 + +#define CONTROL_WMASK (CONTROL_RE | CONTROL_WE | CONTROL_AC) + +#define TYPE_ALTERA_JUART "altera-juart" +#define ALTERA_JUART (obj) \ + OBJECT_CHECK(AlteraJUARTState, (obj), TYPE_ALTERA_JUART) + +/* +* The JTAG UART core generates an interrupt when either of the individual +* interrupt conditions is pending and enabled. +*/ +static void altera_juart_update_irq (AlteraJUARTState *s) +{ +unsigned int irq; + + irq = ((s->jcontrol &CONTROL_WE ) && (s->jcontrol &CONTROL_WI )) || + ((s->jcontrol &CONTROL_RE ) && (s->jcontrol &CONTROL_RI ));
hw/char/altera_juart.c line 63
Quoted 10 lines
hw/char/altera_juart.c new file +10
-0+ +qemu_set_irq (s->irq, irq); +} + +static uint64_t altera_juart_read (void *opaque,hwaddr addr,unsigned int size) +{ +AlteraJUARTState *s = opaque; +uint32_t r; + + addr >>=2 ;
Hmmmmm, how will unaligned read from one of these registers be handled on real HW ? ie. read from address 0x3 ? What about writes ?
Quoted 18 lines
hw/char/altera_juart.c new file +18
-0+switch (addr) { +case R_DATA : + r = s->rx_fifo[(s->rx_fifo_pos - s->rx_fifo_len) & (FIFO_LENGTH -1 )]; +if (s->rx_fifo_len) { + s->rx_fifo_len--; +qemu_chr_fe_accept_input (&s->chr); + s->jdata = r |DATA_RVALID | (s->rx_fifo_len <<16 ); + s->jcontrol |=CONTROL_RI ; + }else { + s->jdata =0 ; + s->jcontrol &= ~CONTROL_RI ; + } + +altera_juart_update_irq (s); +return s->jdata; + +case R_CONTROL : +return s->jcontrol;
hw/char/altera_juart.c line 92
Quoted 10 lines
hw/char/altera_juart.c new file +10
-0+ } + +return 0 ; +} + +static void altera_juart_write (void *opaque,hwaddr addr, +uint64_t val64,unsigned int size) +{ +AlteraJUARTState *s = opaque; +uint32_t value = val64;
Is this needed ?
Quoted 11 lines
hw/char/altera_juart.c new file +11
-0+unsigned char c; + + addr >>=2 ; + +switch (addr) { +case R_DATA : + c = value &0xFF ; +/* +* We do not decrement the write fifo, +* we "tranmsmit" instanteniously, CONTROL_WI always asserted +*/
hw/char/altera_juart.c line 113
Quoted 10 lines
hw/char/altera_juart.c new file +10
-0+ s->jcontrol |=CONTROL_WI ; + s->jdata = c; +qemu_chr_fe_write (&s->chr, &c,1 ); +altera_juart_update_irq (s); +break ; + +case R_CONTROL : +/* Only RE and WE are writable */ + value &=CONTROL_WMASK ; + s->jcontrol &= ~(CONTROL_WMASK );
The parenthesis are not needed.
Quoted 8 lines
hw/char/altera_juart.c new file +8
-0+ s->jcontrol |= value; + +/* Writing 1 to AC clears it to 0 */ +if (value &CONTROL_AC ) { + s->jcontrol &= ~CONTROL_AC ; + } +altera_juart_update_irq (s); +break ;
hw/char/altera_juart.c line 131
Quoted 10 lines
hw/char/altera_juart.c new file +10
-0+ } +} + +static void altera_juart_receive (void *opaque,const uint8_t *buf,int size) +{ +int i; +AlteraJUARTState *s = opaque; + +if (s->rx_fifo_len >=FIFO_LENGTH ) { +fprintf (stderr,"WARNING: UART dropped char.\n" );
Can this ever happen ? can_receive will IMO prevent this case.
Quoted 12 lines
hw/char/altera_juart.c new file +12
-0+return ; + } + +for (i =0 ; i < size; i++) { + s->rx_fifo[s->rx_fifo_pos] = buf[i]; + s->rx_fifo_pos++; + s->rx_fifo_pos &= (FIFO_LENGTH -1 ); + s->rx_fifo_len++; + } + s->jcontrol |=CONTROL_RI ; +altera_juart_update_irq (s); +}
[...]
Quoted 23 lines
include/hw/char/altera_juart.h new file +17
-0@@ -0,0 +1,44 @@ +/* +* Altera JTAG UART emulation +* +* Copyright (c) 2016-2017 Intel Corporation. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef ALTERA_JUART_H +#define ALTERA_JUART_H +
include/hw/char/altera_juart.h line 27
Quoted 10 lines
include/hw/char/altera_juart.h new file +10
-0+#include "hw/sysbus.h" +#include "sysemu/char.h" + +/* +* The read and write FIFO depths can be set from 8 to 32,768 bytes. +* Only powers of two are allowed. A depth of 64 is generally optimal for +* performance, and larger values are rarely necessary. +*/ + +#define FIFO_LENGTH 64
Should probably be a QOM property, no ?
Quoted 7 lines
include/hw/char/altera_juart.h new file +6
-0+typedef struct AlteraJUARTState { + SysBusDevice busdev; + MemoryRegion mmio; + CharBackend chr; + qemu_irq irq; +
include/hw/char/altera_juart.h line 44
Quoted 10 lines
include/hw/char/altera_juart.h new file +10
-0+unsigned int rx_fifo_pos; +unsigned int rx_fifo_len; +uint32_t jdata; +uint32_t jcontrol; + uint8_t rx_fifo[FIFO_LENGTH]; +} AlteraJUARTState; + +void altera_juart_create (int channel,const hwaddr addr,qemu_irq irq); + +#endif /* ALTERA_JUART_H */
btw for trivial patches like this, cover letter is not necessary .
Signature · 2 lines
Best regards, Marek Vasut
Quoted 10 lines · Marek Vasut
Quoted 7 lines · Juro Bystricky
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.Isn't QEMU GPLv2 only and NOT GPLv2+ ?
As a binary as a whole QEMU is GPLv2, because that is the most restrictive and thus the controlling license. Individual source files are under a variety of licenses, which is fine as long as those licenses are GPL-2-compatible. We have a preference against 2-only (see the LICENSE file), and also you should at least use a license we're already using. GPL2-or-later is fine and a common choice.
Quoted 1 line
btw for trivial patches like this, cover letter is not necessary .
The rough rule is "single patches don't need a cover letter; series of more than one patch always do."
thanks
-- PMM
Quoted 4 lines
Please make the commit message a bit more verbose, looking just at the commit message, I have no clue what patch I'm looking at. The embedded IP UG also has like 30 cores in it, so some detail on which core and in which chapter/page would help.
OK, will do
Quoted 6 lines
Quoted 3 lines
+ * The Altera JTAG UART hardware registers are described in:
+ * https://www.altera.com/en_US/pdfs/literature/ug/ug_embedded_ip.pdf
+ *Drop the trailing newline
OK, will do
Quoted 11 lines
Quoted 1 line
+static
uint64_taltera_juart_read(void *opaque, hwaddr addr, unsignedint size)
hw/char/altera_juart.c line 63
Quoted 5 lines
hw/char/altera_juart.c new file +5
-0+{ +AlteraJUARTState *s = opaque; +uint32_t r; + + addr >>=2 ;Hmmmmm, how will unaligned read from one of these registers be handled on real HW ? ie. read from address
0x3? What about writes ?
there is no reading/writing going on via "addr".
This just maps the hw address into register number, where registers are at 4 bytes boundaries (so they are aligned as needed) but indexed as 1,2,3.... (Pretty common code in other drivers.)
But will redo the code anyway so there are no shifts.
Quoted 7 lines
hw/char/altera_juart.c line 92
Quoted 5 lines
hw/char/altera_juart.c new file +5
-0+static void altera_juart_write (void *opaque,hwaddr addr, +uint64_t val64,unsigned int size) +{ +AlteraJUARTState *s = opaque; +uint32_t value = val64;Is this needed ?
Good question. Legacy code, probably not needed anymore. Same inextraxfs_ser.c, Xilinx_uartlite.c, stm32f2xx_usart.c.
I suspect in the past some compiler generated warnings about type mismatch (32/64). Will remove.
Quoted 16 lines
Quoted 16 lines
hw/char/altera_juart.c new file +15
-0+unsigned char c; + + addr >>=2 ; + +switch (addr) { +case R_DATA : + c = value &0xFF ; +/* +* We do not decrement the write fifo, +* we "tranmsmit" instanteniously, CONTROL_WI always asserted +*/ + s->jcontrol |=CONTROL_WI ; + s->jdata = c; +qemu_chr_fe_write (&s->chr, &c,1 ); +altera_juart_update_irq (s);
Quoted 8 lines
hw/char/altera_juart.c line 113
Quoted 6 lines
hw/char/altera_juart.c new file +6
-0+break ; + +case R_CONTROL : +/* Only RE and WE are writable */ + value &=CONTROL_WMASK ; + s->jcontrol &= ~(CONTROL_WMASK );The parenthesis are not needed.
OK, will remove them
Quoted 12 lines
Quoted 2 lines
+static void altera_juart_receive(void *opaque, const
uint8_t*buf, intsize)
hw/char/altera_juart.c line 131
Quoted 6 lines
hw/char/altera_juart.c new file +6
-0+{ +int i; +AlteraJUARTState *s = opaque; + +if (s->rx_fifo_len >=FIFO_LENGTH ) { +fprintf (stderr,"WARNING: UART dropped char.\n" );Can this ever happen ?
can_receivewill IMO prevent this case.
Fair question. I did not go through all QEMU code to see when/where
in the bowels of QEMU can_receive is actually called. If it is always called prior "receive", then this check may be redundant. Again, there are other serial drivers that do this check as well (etraxfs, Xilinx,...)
But most don't, so I'll follow the majority and remove it.
Quoted 32 lines
Review
Quoted 1 line
(quoted diff) +0
-0
b/include/hw/char/altera_juart.hQuoted 6 lines
new file mode 100644
index 0000000..8a9c892include/hw/char/altera_juart.h new file +1
-0@@ -0,0 +1,44 @@ +/* include/hw/char/altera_juart.h line 11
Quoted 10 lines
include/hw/char/altera_juart.h new file +10
-0+* Altera JTAG UART emulation +* +* Copyright (c) 2016-2017 Intel Corporation. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +* You should have received a copy of the GNU General Public License along
include/hw/char/altera_juart.h
Quoted 12 lines
include/hw/char/altera_juart.h new file +12
-0+* with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef ALTERA_JUART_H +#define ALTERA_JUART_H + +#include "hw/sysbus.h" +#include "sysemu/char.h" + +/* +* The read and write FIFO depths can be set from 8 to 32,768 bytes. +* Only powers of two are allowed. A depth of 64 is generally optimal for
Quoted 6 lines
include/hw/char/altera_juart.h line 27
Quoted 4 lines
include/hw/char/altera_juart.h new file +4
-0+* performance, and larger values are rarely necessary. +*/ + +#define FIFO_LENGTH 64Should probably be a QOM property, no ?
Did not want to mess with dynamic FIFO buffer allocation.
Quoted 11 lines
Quoted 11 lines
include/hw/char/altera_juart.h new file +10
-0+typedef struct AlteraJUARTState { + SysBusDevice busdev; + MemoryRegion mmio; + CharBackend chr; + qemu_irq irq; + + unsigned int rx_fifo_pos; + unsigned int rx_fifo_len; + uint32_t jdata; + uint32_t jcontrol;
Quoted 8 lines
include/hw/char/altera_juart.h line 44
Quoted 7 lines
include/hw/char/altera_juart.h new file +6
-0+ uint8_t rx_fifo[FIFO_LENGTH]; +} AlteraJUARTState; + +void altera_juart_create (int channel,const hwaddr addr,qemu_irq irq); + +#endif /* ALTERA_JUART_H */ btw for trivial patches like this, cover letter is not necessary .
Thanks, good to know, makes life easier
Juro
On 02/09/2017 01:54 AM, Bystricky, Juro wrote:
[...]
Quoted 12 lines
Quoted 11 lines
Quoted 1 line
+static
uint64_taltera_juart_read(void *opaque, hwaddr addr, unsignedint size)
hw/char/altera_juart.c line 63
Quoted 5 lines
hw/char/altera_juart.c new file +5
-0+{ +AlteraJUARTState *s = opaque; +uint32_t r; + + addr >>=2 ;Hmmmmm, how will unaligned read from one of these registers be handled on real HW ? ie. read from address
0x3? What about writes ?
Quoted 5 lines
there is no reading/writing going on via "addr".
This just maps the hw address into register number, where registers are at 4 bytes boundaries (so they are aligned as needed) but indexed as 1,2,3.... (Pretty common code in other drivers.)
But will redo the code anyway so there are no shifts.
This doesn't answer my question at all. How does real hardware behave if you read from unaligned address in the register space , ie. offset 0x3 ?
[...]
Quoted 12 lines
Quoted 11 lines
Quoted 1 line
+static void altera_juart_receive(void *opaque, const
uint8_t*buf, intsize)
hw/char/altera_juart.c line 131
Quoted 6 lines
hw/char/altera_juart.c new file +6
-0+{ +int i; +AlteraJUARTState *s = opaque; + +if (s->rx_fifo_len >=FIFO_LENGTH ) { +fprintf (stderr,"WARNING: UART dropped char.\n" );Can this ever happen ?
can_receivewill IMO prevent this case.
Quoted 4 lines
Fair question. I did not go through all QEMU code to see when/where
in the bowels of QEMUcan_receiveis actually called. If it is always called prior "receive", then this check may be redundant. Again, there are other serial drivers that do this check as well (etraxfs, Xilinx,...)
But most don't, so I'll follow the majority and remove it.
Maybe you can check the core code or someone else can jump in an answer this.
Quoted 32 lines
Quoted 32 lines
Review
Quoted 1 line
(quoted diff) +0
-0
b/include/hw/char/altera_juart.hQuoted 6 lines
new file mode 100644
index 0000000..8a9c892include/hw/char/altera_juart.h new file +1
-0@@ -0,0 +1,44 @@ +/* include/hw/char/altera_juart.h line 11
Quoted 10 lines
include/hw/char/altera_juart.h new file +10
-0+* Altera JTAG UART emulation +* +* Copyright (c) 2016-2017 Intel Corporation. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +* You should have received a copy of the GNU General Public License along
include/hw/char/altera_juart.h
Quoted 12 lines
include/hw/char/altera_juart.h new file +12
-0+* with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef ALTERA_JUART_H +#define ALTERA_JUART_H + +#include "hw/sysbus.h" +#include "sysemu/char.h" + +/* +* The read and write FIFO depths can be set from 8 to 32,768 bytes. +* Only powers of two are allowed. A depth of 64 is generally optimal for
Quoted 8 lines
Quoted 6 lines
include/hw/char/altera_juart.h line 27
Quoted 4 lines
include/hw/char/altera_juart.h new file +4
-0+* performance, and larger values are rarely necessary. +*/ + +#define FIFO_LENGTH 64Should probably be a QOM property, no ?
Did not want to mess with dynamic FIFO buffer allocation.
You probably should, since this is configurable at the FPGA level (in QSys), right ?
Quoted 22 lines
Quoted 10 lines
Quoted 10 lines
include/hw/char/altera_juart.h new file +10
-0+typedef struct AlteraJUARTState { + SysBusDevice busdev; + MemoryRegion mmio; + CharBackend chr; + qemu_irq irq; + + unsigned int rx_fifo_pos; + unsigned int rx_fifo_len; + uint32_t jdata; + uint32_t jcontrol;Quoted 8 lines
include/hw/char/altera_juart.h line 44
Quoted 7 lines
include/hw/char/altera_juart.h new file +6
-0+ uint8_t rx_fifo[FIFO_LENGTH]; +} AlteraJUARTState; + +void altera_juart_create (int channel,const hwaddr addr,qemu_irq irq); + +#endif /* ALTERA_JUART_H */ btw for trivial patches like this, cover letter is not necessary .
Thanks, good to know, makes life easier
Juro
Signature · 2 lines
Best regards, Marek Vasut
Quoted 18 lines
[...]
Quoted 12 lines
Quoted 11 lines
Quoted 1 line
+static
uint64_taltera_juart_read(void *opaque, hwaddr addr, unsignedint size)
hw/char/altera_juart.c line 63
Quoted 5 lines
hw/char/altera_juart.c new file +5
-0+{ +AlteraJUARTState *s = opaque; +uint32_t r; + + addr >>=2 ;Hmmmmm, how will unaligned read from one of these registers be handled on real HW ? ie. read from address
0x3? What about writes ?Quoted 2 lines
there is no reading/writing going on via "addr".
This just maps the hw address into register number, where registers are
Quoted 9 lines
at
Quoted 1 line
4 bytes boundaries (so they are aligned as needed) but indexed as
1,2,3....
Quoted 2 lines
(Pretty common code in other drivers.)
But will redo the code anyway so there are no shifts.This doesn't answer my question at all. How does real hardware behave if you read from unaligned address in the register space , ie. offset
0x3?
Not sure I understand the question here. Which "real hardware" are we talking about? If "real hardware" contains MMU or MPU then an exception is generated on misalign access.
Quoted 14 lines
[...]
Quoted 12 lines
Quoted 11 lines
Quoted 1 line
+static void altera_juart_receive(void *opaque, const
uint8_t*buf, intsize)
hw/char/altera_juart.c line 131
Quoted 6 lines
hw/char/altera_juart.c new file +6
-0+{ +int i; +AlteraJUARTState *s = opaque; + +if (s->rx_fifo_len >=FIFO_LENGTH ) { +fprintf (stderr,"WARNING: UART dropped char.\n" );Can this ever happen ?
can_receivewill IMO prevent this case.
Quoted 8 lines
Quoted 2 lines
Fair question. I did not go through all QEMU code to see when/where in the bowels of QEMU
can_receiveis actually called. If it is alwayscalled prior "receive", then this check may be redundant. Again, there are
Quoted 2 lines
other serial drivers that do this check as well (etraxfs, Xilinx,...) But most don't, so I'll follow the majority and remove it.
Maybe you can check the core code or someone else can jump in an answer this.
OK, will look deeper
[...]
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
include/hw/char/altera_juart.h
Quoted 9 lines
include/hw/char/altera_juart.h new file +9
-0+#ifndef ALTERA_JUART_H +#define ALTERA_JUART_H + +#include "hw/sysbus.h" +#include "sysemu/char.h" + +/* +* The read and write FIFO depths can be set from 8 to 32,768 bytes. +* Only powers of two are allowed. A depth of 64 is generally optimal for
include/hw/char/altera_juart.h line 27
Quoted 4 lines
+ * performance, and larger values are rarely necessary.
+ */include/hw/char/altera_juart.h new file +2
-0+ +#define FIFO_LENGTH 64Should probably be a QOM property, no ?
Quoted 5 lines
Quoted 1 line
Did not want to mess with dynamic FIFO buffer allocation.
You probably should, since this is configurable at the FPGA level (in QSys), right ?
OK, will implement fifo size as a property
Thanks
Juro
Quoted 21 lines · Juro
Quoted 21 lines
[...]
Quoted 12 lines
Quoted 11 lines
Quoted 1 line
+static
uint64_taltera_juart_read(void *opaque, hwaddr addr, unsignedint size)
hw/char/altera_juart.c line 63
Quoted 5 lines
hw/char/altera_juart.c new file +5
-0+{ +AlteraJUARTState *s = opaque; +uint32_t r; + + addr >>=2 ;Hmmmmm, how will unaligned read from one of these registers be handled on real HW ? ie. read from address
0x3? What about writes ?Quoted 2 lines
there is no reading/writing going on via "addr".
This just maps the hw address into register number, where registers areat
Quoted 1 line
4 bytes boundaries (so they are aligned as needed) but indexed as
1,2,3....
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
(Pretty common code in other drivers.)
But will redo the code anyway so there are no shifts.This doesn't answer my question at all. How does real hardware behave if you read from unaligned address in the register space , ie. offset
0x3?Not sure I understand the question here. Which "real hardware" are we talking about?
By real hardware I mean real Nios2 system ...
Quoted 1 line
If "real hardware" contains MMU or MPU then an exception is generated on misalign access.
Is this handled here or not ?
Quoted 56 lines
Quoted 14 lines
[...]
Quoted 12 lines
Quoted 11 lines
Quoted 1 line
+static void altera_juart_receive(void *opaque, const
uint8_t*buf, intsize)
hw/char/altera_juart.c line 131
Quoted 6 lines
hw/char/altera_juart.c new file +6
-0+{ +int i; +AlteraJUARTState *s = opaque; + +if (s->rx_fifo_len >=FIFO_LENGTH ) { +fprintf (stderr,"WARNING: UART dropped char.\n" );Can this ever happen ?
can_receivewill IMO prevent this case.Quoted 8 lines
Quoted 2 lines
Fair question. I did not go through all QEMU code to see when/where in the bowels of QEMU
can_receiveis actually called. If it is alwayscalled prior "receive", then this check may be redundant. Again, there are
Quoted 2 lines
other serial drivers that do this check as well (etraxfs, Xilinx,...) But most don't, so I'll follow the majority and remove it.
Maybe you can check the core code or someone else can jump in an answer this.
OK, will look deeper
[...]
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
include/hw/char/altera_juart.h
Quoted 9 lines
include/hw/char/altera_juart.h new file +9
-0+#ifndef ALTERA_JUART_H +#define ALTERA_JUART_H + +#include "hw/sysbus.h" +#include "sysemu/char.h" + +/* +* The read and write FIFO depths can be set from 8 to 32,768 bytes. +* Only powers of two are allowed. A depth of 64 is generally optimal for
include/hw/char/altera_juart.h line 27
Quoted 4 lines
+ * performance, and larger values are rarely necessary.
+ */include/hw/char/altera_juart.h new file +2
-0+ +#define FIFO_LENGTH 64Should probably be a QOM property, no ?
Quoted 5 lines
Quoted 1 line
Did not want to mess with dynamic FIFO buffer allocation.
You probably should, since this is configurable at the FPGA level (in QSys), right ?
OK, will implement fifo size as a property
Thanks
Juro
Signature · 2 lines
Best regards, Marek Vasut
Quoted 28 lines
Quoted 3 lines
Quoted 3 lines
[...]
Quoted 1 line
Quoted 1 line
Quoted 1 line
+static
uint64_taltera_juart_read(void *opaque, hwaddr addr,unsigned
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 10 lines
int size)
hw/char/altera_juart.c line 63
Quoted 5 lines
hw/char/altera_juart.c new file +5
-0+{ +AlteraJUARTState *s = opaque; +uint32_t r; + + addr >>=2 ;Hmmmmm, how will unaligned read from one of these registers be handled on real HW ? ie. read from address
0x3? What about writes ?Quoted 2 lines
there is no reading/writing going on via "addr".
This just maps the hw address into register number, where registers areat
Quoted 1 line
4 bytes boundaries (so they are aligned as needed) but indexed as
1,2,3....
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
(Pretty common code in other drivers.)
But will redo the code anyway so there are no shifts.This doesn't answer my question at all. How does real hardware behave if you read from unaligned address in the register space , ie. offset
0x3?Not sure I understand the question here. Which "real hardware" are we
Quoted 9 lines
talking about?
By real hardware I mean real Nios2 system ...
Quoted 1 line
If "real hardware" contains MMU or MPU then an exception is generated on
misalign access.
Is this handled here or not ?
Sorry, I am not sure I understand the question. Exceptions are handled by interrupt controller.
This code for JTAG UART does not have any misaligned accesses.
Quoted 33 lines · Juro
Quoted 33 lines
Quoted 3 lines
Quoted 3 lines
[...]
Quoted 1 line
Quoted 1 line
Quoted 1 line
+static
uint64_taltera_juart_read(void *opaque, hwaddr addr,unsigned
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 10 lines
int size)
Review
Quoted 5 lines
(quoted diff) +5
-0+{ + AlteraJUARTState *s = opaque; + uint32_t r; + + addr >>= 2;Hmmmmm, how will unaligned read from one of these registers be handled on real HW ? ie. read from address
0x3? What about writes ?Quoted 2 lines
there is no reading/writing going on via "addr".
This just maps the hw address into register number, where registers areat
Quoted 1 line
4 bytes boundaries (so they are aligned as needed) but indexed as
1,2,3....
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
(Pretty common code in other drivers.)
But will redo the code anyway so there are no shifts.This doesn't answer my question at all. How does real hardware behave if you read from unaligned address in the register space , ie. offset
0x3?Not sure I understand the question here. Which "real hardware" are we
talking about?
By real hardware I mean real Nios2 system ...
Quoted 1 line
If "real hardware" contains MMU or MPU then an exception is generated on
Quoted 10 lines
Quoted 4 lines
misalign access.
Is this handled here or not ?
Sorry, I am not sure I understand the question. Exceptions are handled by interrupt controller.
This code for JTAG UART does not have any misaligned accesses.
The code running on nios2 can issue unaligned access to the jtag uart registers, yes ? If that happens, what happens on real HW and how is this emulated ?
Signature · 2 lines
Best regards, Marek Vasut
Quoted 3 lines
The code running on nios2 can issue unaligned access to the jtag uart registers, yes ? If that happens, what happens on real HW and how is this emulated ?
Misaligned accesses to any registers would raise an exception. The exception is handled by interrupt controller, either "real" or emulated. Such access should never reach code for jtag uart.
Also note we only allow access size 4 in the code:
static const MemoryRegionOps juart_ops = {
.read = altera_juart_read,
.write = altera_juart_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4,
.max_access_size = 4
}
};
Thanks
Juro
Quoted 10 lines · Juro
Quoted 3 lines
The code running on nios2 can issue unaligned access to the jtag uart registers, yes ? If that happens, what happens on real HW and how is this emulated ?
Misaligned accesses to any registers would raise an exception. The exception is handled by interrupt controller, either "real" or emulated. Such access should never reach code for jtag uart.
Also note we only allow access size 4 in the code:
Quoted 9 lines
static const MemoryRegionOps
juart_ops= {
.read =altera_juart_read,
.write =altera_juart_write,
.endianness =DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4,
.max_access_size = 4
}
};
This answers my question , thanks.
Signature · 2 lines
Best regards, Marek Vasut