Re: [Qemu-devel] [PATCH V4 4/7] CAN bus Kvaser PCI CAN-S (single SJA1000 channel) emulation added.

2018-03-07 Thread Paolo Bonzini
On 06/03/2018 21:52, Pavel Pisa wrote:
> Hello Thomas,
> 
> thanks for report but I at this time I am and
> can be some time in condition which does not allow
> me to access e-mail and normal work
> 
> On Tuesday 06 of March 2018 16:29:19 Thomas Huth wrote:
>> On 14.01.2018 21:14, p...@cmp.felk.cvut.cz wrote:
>>> From: Pavel Pisa 
>>>
>>> Signed-off-by: Pavel Pisa 
>>> ---
>>>  default-configs/pci.mak |   1 +
>>>  hw/can/Makefile.objs|   1 +
>>>  hw/can/can_kvaser_pci.c | 375
>>>  3 files changed, 377
>>> insertions(+)
>>>  create mode 100644 hw/can/can_kvaser_pci.c
>>
>>  Hi,
>>
>> the kvaser_pci device introduced a new way to crash QEMU, e.g.:
>>
>> mips64el-softmmu/qemu-system-mips64el -M malta,accel=qtest \
>>   -device kvaser_pci
>>
>> Program received signal SIGSEGV, Segmentation fault.
>> 0x55a6e2ec in can_bus_insert_client (bus=0x0,
>> client=client@entry=0x570c4018) at
>> /home/thuth/devel/qemu/net/can/can_core.c:50
>> 50   QTAILQ_INSERT_TAIL(>clients, client, next);
> 
> The reason is that parameters canbus0 and canbus1 are required.
> 
>   -object can-bus,id=canbus0 \
>   -device kvaser_pci,canbus0=canbus0
> 
> This could be be fast fix but plead somebody else to send regular
> patch.
> 
> --- a/net/can/can_host.c
> +++ b/net/can/can_host.c
> @@ -57,6 +57,10 @@ static void can_host_connect(CanHostState *ch, Error 
> **errp)
>  return;
>  }
> 
> +if (ch->bus_client == NULL) {
> +error_setg(errp, "bus is not specified for given device.");
> +return;
> +}
>  can_bus_insert_client(ch->bus, >bus_client);
>  }

Ok, I'll check it out.

Thanks Thomas for the report!

Paolo



Re: [Qemu-devel] [PATCH V4 4/7] CAN bus Kvaser PCI CAN-S (single SJA1000 channel) emulation added.

2018-03-06 Thread Pavel Pisa
Hello Thomas,

thanks for report but I at this time I am and
can be some time in condition which does not allow
me to access e-mail and normal work

On Tuesday 06 of March 2018 16:29:19 Thomas Huth wrote:
> On 14.01.2018 21:14, p...@cmp.felk.cvut.cz wrote:
> > From: Pavel Pisa 
> >
> > Signed-off-by: Pavel Pisa 
> > ---
> >  default-configs/pci.mak |   1 +
> >  hw/can/Makefile.objs|   1 +
> >  hw/can/can_kvaser_pci.c | 375
> >  3 files changed, 377
> > insertions(+)
> >  create mode 100644 hw/can/can_kvaser_pci.c
>
>  Hi,
>
> the kvaser_pci device introduced a new way to crash QEMU, e.g.:
>
> mips64el-softmmu/qemu-system-mips64el -M malta,accel=qtest \
>   -device kvaser_pci
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x55a6e2ec in can_bus_insert_client (bus=0x0,
> client=client@entry=0x570c4018) at
> /home/thuth/devel/qemu/net/can/can_core.c:50
> 50QTAILQ_INSERT_TAIL(>clients, client, next);

The reason is that parameters canbus0 and canbus1 are required.

  -object can-bus,id=canbus0 \
  -device kvaser_pci,canbus0=canbus0

This could be be fast fix but plead somebody else to send regular
patch.

--- a/net/can/can_host.c
+++ b/net/can/can_host.c
@@ -57,6 +57,10 @@ static void can_host_connect(CanHostState *ch, Error **errp)
 return;
 }

+if (ch->bus_client == NULL) {
+error_setg(errp, "bus is not specified for given device.");
+return;
+}
 can_bus_insert_client(ch->bus, >bus_client);
 }


My personal opinion is to create bus on 

Best wishes,

Pavel Pisa



Re: [Qemu-devel] [PATCH V4 4/7] CAN bus Kvaser PCI CAN-S (single SJA1000 channel) emulation added.

2018-03-06 Thread Thomas Huth
On 14.01.2018 21:14, p...@cmp.felk.cvut.cz wrote:
> From: Pavel Pisa 
> 
> Signed-off-by: Pavel Pisa 
> ---
>  default-configs/pci.mak |   1 +
>  hw/can/Makefile.objs|   1 +
>  hw/can/can_kvaser_pci.c | 375 
> 
>  3 files changed, 377 insertions(+)
>  create mode 100644 hw/can/can_kvaser_pci.c

 Hi,

the kvaser_pci device introduced a new way to crash QEMU, e.g.:

mips64el-softmmu/qemu-system-mips64el -M malta,accel=qtest \
  -device kvaser_pci

Program received signal SIGSEGV, Segmentation fault.
0x55a6e2ec in can_bus_insert_client (bus=0x0, 
client=client@entry=0x570c4018)
at /home/thuth/devel/qemu/net/can/can_core.c:50
50  QTAILQ_INSERT_TAIL(>clients, client, next);
(gdb) bt
#0  0x55a6e2ec in can_bus_insert_client (bus=0x0, 
client=client@entry=0x570c4018)
at /home/thuth/devel/qemu/net/can/can_core.c:50
#1  0x559d7364 in can_sja_connect_to_bus (s=s@entry=0x570c3f80, 
bus=)
at /home/thuth/devel/qemu/hw/net/can/can_sja1000.c:869
#2  0x559d75a4 in kvaser_pci_realize (pci_dev=0x570c33d0, 
errp=0x7fffd8e0)
at /home/thuth/devel/qemu/hw/net/can/can_kvaser_pci.c:230
#3  0x559e12f1 in pci_qdev_realize (qdev=0x570c33d0, 
errp=0x7fffd980)
at /home/thuth/devel/qemu/hw/pci/pci.c:2029
#4  0x55963c3a in device_set_realized (obj=, 
value=, errp=0x7fffdab8)
at /home/thuth/devel/qemu/hw/core/qdev.c:852
#5  0x55aa7a7e in property_set_bool (obj=0x570c33d0, v=, name=, opaque=0x56f6d220, errp=0x7fffdab8) at 
/home/thuth/devel/qemu/qom/object.c:1906
#6  0x55aabbef in object_property_set_qobject 
(obj=obj@entry=0x570c33d0, value=value@entry=0x570c4a60, 
name=name@entry=0x55c7079f "realized", errp=errp@entry=0x7fffdab8)
at /home/thuth/devel/qemu/qom/qom-qobject.c:27
#7  0x55aa9860 in object_property_set_bool (obj=0x570c33d0, 
value=, name=0x55c7079f "realized", errp=0x7fffdab8) at 
/home/thuth/devel/qemu/qom/object.c:1171
#8  0x558eb1d9 in qdev_device_add (opts=0x5689ff40, 
errp=errp@entry=0x7fffdb90)
at /home/thuth/devel/qemu/qdev-monitor.c:634
#9  0x558ed547 in device_init_func (opaque=, 
opts=, errp=)
at /home/thuth/devel/qemu/vl.c:2350
#10 0x55b8d75a in qemu_opts_foreach (list=, 
func=func@entry=
0x558ed520 , opaque=opaque@entry=0x0, 
errp=errp@entry=0x0)
at /home/thuth/devel/qemu/util/qemu-option.c:1073
#11 0x557b8f64 in main (argc=, argv=, 
envp=)
at /home/thuth/devel/qemu/vl.c:4618

Could you please fix this?

 Thanks,
  Thomas



Re: [Qemu-devel] [PATCH V4 4/7] CAN bus Kvaser PCI CAN-S (single SJA1000 channel) emulation added.

2018-01-14 Thread Philippe Mathieu-Daudé
On 01/14/2018 05:14 PM, p...@cmp.felk.cvut.cz wrote:
> From: Pavel Pisa 
> 
> Signed-off-by: Pavel Pisa 
> ---
>  default-configs/pci.mak |   1 +
>  hw/can/Makefile.objs|   1 +
>  hw/can/can_kvaser_pci.c | 375 
> 
>  3 files changed, 377 insertions(+)
>  create mode 100644 hw/can/can_kvaser_pci.c
> 
> diff --git a/default-configs/pci.mak b/default-configs/pci.mak
> index 979b649fe5..72c0802ced 100644
> --- a/default-configs/pci.mak
> +++ b/default-configs/pci.mak
> @@ -33,6 +33,7 @@ CONFIG_SERIAL_ISA=y
>  CONFIG_SERIAL_PCI=y
>  CONFIG_CAN_CORE=y
>  CONFIG_CAN_SJA1000=y
> +CONFIG_CAN_PCI=y
>  CONFIG_IPACK=y
>  CONFIG_WDT_IB6300ESB=y
>  CONFIG_PCI_TESTDEV=y
> diff --git a/hw/can/Makefile.objs b/hw/can/Makefile.objs
> index 3c4bf3bfc1..c9d07b9b16 100644
> --- a/hw/can/Makefile.objs
> +++ b/hw/can/Makefile.objs
> @@ -8,4 +8,5 @@ else
>  common-obj-y += can_host_stub.o
>  endif
>  common-obj-$(CONFIG_CAN_SJA1000) += can_sja1000.o
> +common-obj-$(CONFIG_CAN_PCI) += can_kvaser_pci.o
>  endif
> diff --git a/hw/can/can_kvaser_pci.c b/hw/can/can_kvaser_pci.c
> new file mode 100644
> index 00..7e3f28d83c
> --- /dev/null
> +++ b/hw/can/can_kvaser_pci.c
> @@ -0,0 +1,375 @@
> +/*
> + * Kvaser PCI CAN device (SJA1000 based) emulation
> + *
> + * Copyright (c) 2013-2014 Jin Yang
> + * Copyright (c) 2014-2018 Pavel Pisa
> + *
> + * Partially based on educational PCIexpress APOHW hardware
> + * emulator used fro class A0B36APO at CTU FEE course by
> + *Rostislav Lisovy and Pavel Pisa
> + *
> + * Initial development supported by Google GSoC 2013 from RTEMS project slot
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu/event_notifier.h"
> +#include "qemu/thread.h"
> +#include "qemu/sockets.h"
> +#include "qemu/error-report.h"
> +#include "chardev/char.h"
> +#include "hw/hw.h"
> +#include "hw/pci/pci.h"
> +#include "can/can_emu.h"
> +
> +#include "can_sja1000.h"
> +
> +#define TYPE_CAN_PCI_DEV "kvaser_pci"
> +
> +#define KVASER_PCI_DEV(obj) \
> +OBJECT_CHECK(KvaserPCIState, (obj), TYPE_CAN_PCI_DEV)
> +
> +#ifndef KVASER_PCI_VENDOR_ID1
> +#define KVASER_PCI_VENDOR_ID1 0x10e8/* the PCI device and vendor IDs 
> */
> +#endif
> +
> +#ifndef KVASER_PCI_DEVICE_ID1
> +#define KVASER_PCI_DEVICE_ID1 0x8406
> +#endif
> +
> +#define KVASER_PCI_S5920_RANGE0x80
> +#define KVASER_PCI_SJA_RANGE  0x80
> +#define KVASER_PCI_XILINX_RANGE   0x8
> +
> +#define KVASER_PCI_BYTES_PER_SJA  0x20
> +
> +#define S5920_OMB 0x0C
> +#define S5920_IMB 0x1C
> +#define S5920_MBEF0x34
> +#define S5920_INTCSR  0x38
> +#define S5920_RCR 0x3C
> +#define S5920_PTCR0x60
> +
> +#define S5920_INTCSR_ADDON_INTENABLE_M0x2000
> +#define S5920_INTCSR_INTERRUPT_ASSERTED_M 0x80
> +
> +#define KVASER_PCI_XILINX_VERINT  7   /* Lower nibble simulate interrupts,
> + high nibble version number. */
> +
> +#define KVASER_PCI_XILINX_VERSION_NUMBER 13
> +
> +typedef struct KvaserPCIState {
> +/*< private >*/
> +PCIDevice   dev;
> +/*< public >*/
> +MemoryRegions5920_io;
> +MemoryRegionsja_io;
> +MemoryRegionxilinx_io;
> +
> +CanSJA1000State sja_state;
> +qemu_irqirq;
> +
> +uint32_ts5920_intcsr;
> +uint32_ts5920_irqstate;
> +
> +char*model; /* The model that support, only SJA1000 now. */
> +char*canbus;
> +char*host;
> +} KvaserPCIState;
> +
> +static void kvaser_pci_irq_raise(void *opaque)
> +{
> +KvaserPCIState *d = (KvaserPCIState *)opaque;
> +d->s5920_irqstate = 1;
> +
> +if (d->s5920_intcsr & S5920_INTCSR_ADDON_INTENABLE_M) {
> +

[Qemu-devel] [PATCH V4 4/7] CAN bus Kvaser PCI CAN-S (single SJA1000 channel) emulation added.

2018-01-14 Thread pisa
From: Pavel Pisa 

Signed-off-by: Pavel Pisa 
---
 default-configs/pci.mak |   1 +
 hw/can/Makefile.objs|   1 +
 hw/can/can_kvaser_pci.c | 375 
 3 files changed, 377 insertions(+)
 create mode 100644 hw/can/can_kvaser_pci.c

diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index 979b649fe5..72c0802ced 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -33,6 +33,7 @@ CONFIG_SERIAL_ISA=y
 CONFIG_SERIAL_PCI=y
 CONFIG_CAN_CORE=y
 CONFIG_CAN_SJA1000=y
+CONFIG_CAN_PCI=y
 CONFIG_IPACK=y
 CONFIG_WDT_IB6300ESB=y
 CONFIG_PCI_TESTDEV=y
diff --git a/hw/can/Makefile.objs b/hw/can/Makefile.objs
index 3c4bf3bfc1..c9d07b9b16 100644
--- a/hw/can/Makefile.objs
+++ b/hw/can/Makefile.objs
@@ -8,4 +8,5 @@ else
 common-obj-y += can_host_stub.o
 endif
 common-obj-$(CONFIG_CAN_SJA1000) += can_sja1000.o
+common-obj-$(CONFIG_CAN_PCI) += can_kvaser_pci.o
 endif
diff --git a/hw/can/can_kvaser_pci.c b/hw/can/can_kvaser_pci.c
new file mode 100644
index 00..7e3f28d83c
--- /dev/null
+++ b/hw/can/can_kvaser_pci.c
@@ -0,0 +1,375 @@
+/*
+ * Kvaser PCI CAN device (SJA1000 based) emulation
+ *
+ * Copyright (c) 2013-2014 Jin Yang
+ * Copyright (c) 2014-2018 Pavel Pisa
+ *
+ * Partially based on educational PCIexpress APOHW hardware
+ * emulator used fro class A0B36APO at CTU FEE course by
+ *Rostislav Lisovy and Pavel Pisa
+ *
+ * Initial development supported by Google GSoC 2013 from RTEMS project slot
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/event_notifier.h"
+#include "qemu/thread.h"
+#include "qemu/sockets.h"
+#include "qemu/error-report.h"
+#include "chardev/char.h"
+#include "hw/hw.h"
+#include "hw/pci/pci.h"
+#include "can/can_emu.h"
+
+#include "can_sja1000.h"
+
+#define TYPE_CAN_PCI_DEV "kvaser_pci"
+
+#define KVASER_PCI_DEV(obj) \
+OBJECT_CHECK(KvaserPCIState, (obj), TYPE_CAN_PCI_DEV)
+
+#ifndef KVASER_PCI_VENDOR_ID1
+#define KVASER_PCI_VENDOR_ID1 0x10e8/* the PCI device and vendor IDs */
+#endif
+
+#ifndef KVASER_PCI_DEVICE_ID1
+#define KVASER_PCI_DEVICE_ID1 0x8406
+#endif
+
+#define KVASER_PCI_S5920_RANGE0x80
+#define KVASER_PCI_SJA_RANGE  0x80
+#define KVASER_PCI_XILINX_RANGE   0x8
+
+#define KVASER_PCI_BYTES_PER_SJA  0x20
+
+#define S5920_OMB 0x0C
+#define S5920_IMB 0x1C
+#define S5920_MBEF0x34
+#define S5920_INTCSR  0x38
+#define S5920_RCR 0x3C
+#define S5920_PTCR0x60
+
+#define S5920_INTCSR_ADDON_INTENABLE_M0x2000
+#define S5920_INTCSR_INTERRUPT_ASSERTED_M 0x80
+
+#define KVASER_PCI_XILINX_VERINT  7   /* Lower nibble simulate interrupts,
+ high nibble version number. */
+
+#define KVASER_PCI_XILINX_VERSION_NUMBER 13
+
+typedef struct KvaserPCIState {
+/*< private >*/
+PCIDevice   dev;
+/*< public >*/
+MemoryRegions5920_io;
+MemoryRegionsja_io;
+MemoryRegionxilinx_io;
+
+CanSJA1000State sja_state;
+qemu_irqirq;
+
+uint32_ts5920_intcsr;
+uint32_ts5920_irqstate;
+
+char*model; /* The model that support, only SJA1000 now. */
+char*canbus;
+char*host;
+} KvaserPCIState;
+
+static void kvaser_pci_irq_raise(void *opaque)
+{
+KvaserPCIState *d = (KvaserPCIState *)opaque;
+d->s5920_irqstate = 1;
+
+if (d->s5920_intcsr & S5920_INTCSR_ADDON_INTENABLE_M) {
+qemu_irq_raise(d->irq);
+}
+}
+
+static void kvaser_pci_irq_lower(void *opaque)
+{
+KvaserPCIState *d = (KvaserPCIState *)opaque;
+d->s5920_irqstate = 0;
+qemu_irq_lower(d->irq);
+}
+
+static void
+kvaser_pci_reset(void *opaque)
+{
+KvaserPCIState *d = (KvaserPCIState *)opaque;
+CanSJA1000State *s = >sja_state;
+
+