All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Cc: qemu-devel@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Marek Vasut" <marex@denx.de>,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Stefan Hajnoczi" <stefanha@gmail.com>,
	"Deniz Eren" <deniz.eren@icloud.com>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Konrad Frederic" <frederic.konrad@adacore.com>,
	"Jan Kiszka" <jan.kiszka@siemens.com>
Subject: Re: [Qemu-devel] [PATCH V4 0/7] CAN bus support for QEMU (SJA1000 PCI so far)
Date: Wed, 24 Jan 2018 18:41:16 -0300	[thread overview]
Message-ID: <abe89c1b-b6fa-3021-fad1-469d2eb2060a@amsat.org> (raw)
In-Reply-To: <201801242122.31033.pisa@cmp.felk.cvut.cz>

Hi Pavel,

On 01/24/2018 05:22 PM, Pavel Pisa wrote:
> Hello everybody,
> 
> On Tuesday 23 of January 2018 22:42:31 Pavel Pisa wrote:
>> When Linux specific object file is linked in then some local
>> function needs to be called before QOM instances population.
>> I know how to do that GCC specific/non-portable way
>>
>> static void __attribute__((constructor)) can_socketcan_setup_variant(void)
>> {
>>
>> }
>>
>> but I expect that something like
>>
>> module_init()
>>
>> in can_socketcan.c should be used.
> 
> 
> I have experimented with code changes to get rid of stub for
> non Linux systems. type_init() is used because it is more
> portable than constructor attribute.
> 
> I have seen that a few other type_init-s do more
> than simple sequence of type_register_static().
> Is it acceptable to use type_init for registration
> to CAN core by function call for now? Conversion simplifies
> makefiles and unnecessary stub file is removed.
> 
> But I would use attribute if that solution is preferred because
> it is allways present on Linux where SocketCAN is used anyway
> and it is used in other Qemu subsystems as well.

using stubs/monitor.c as a template for stubs/can_host_variant.c doesn't
work?

> 
> ----------------------------------------------------------------
> Solution with attribute
> 
> #ifdef TOOLCHAIN_SUPPORTS_ATTRIBUTE_CONSTRUCTOR
> static void __attribute__((constructor))
> can_bus_socketcan_setup(void)
> {
>     can_bus_set_connect_to_host(can_bus_connect_to_host_socketcan);
> }
> #endif
> 
> ----------------------------------------------------------------
> Solution with type_init
> branch https://gitlab.fel.cvut.cz/canbus/qemu-canbus/tree/can-pci-socketcan-init
> 
> diff --git a/hw/can/can_socketcan.c b/hw/can/can_socketcan.c
> index 42099fb696..fb41853c2b 100644
> --- a/hw/can/can_socketcan.c
> +++ b/hw/can/can_socketcan.c
> @@ -309,5 +309,14 @@ static int can_bus_connect_to_host_socketcan(CanBusState *bus,
>      return 0;
>  }
>  
> -int (*can_bus_connect_to_host_variant)(CanBusState *bus, const char *name) =
> -        can_bus_connect_to_host_socketcan;
> +static void can_bus_socketcan_type_init(void)
> +{
> +    /*
> +     * There should be object registration when CanBusSocketcanConnectState
> +     * is converted into QOM object. Use for registration of host
> +     * can bus access for now.
> +     */
> +    can_bus_set_connect_to_host(can_bus_connect_to_host_socketcan);
> +}
> +
> +type_init(can_bus_socketcan_type_init);
> 
> 
> diff --git a/hw/can/Makefile.objs b/hw/can/Makefile.objs
> index 1ce9950de0..14c2369718 100644
> --- a/hw/can/Makefile.objs
> +++ b/hw/can/Makefile.objs
> @@ -2,11 +2,7 @@
>  
>  ifeq ($(CONFIG_CAN_BUS),y)
>  common-obj-y += can_core.o
> -ifeq ($(CONFIG_LINUX),y)
> -common-obj-y += can_socketcan.o
> -else
> -common-obj-y += can_host_stub.o
> -endif
> +common-obj-$(CONFIG_LINUX) += can_socketcan.o
>  common-obj-$(CONFIG_CAN_SJA1000) += can_sja1000.o
>  common-obj-$(CONFIG_CAN_PCI) += can_kvaser_pci.o
>  common-obj-$(CONFIG_CAN_PCI) += can_pcm3680_pci.o
> diff --git a/hw/can/can_core.c b/hw/can/can_core.c
> index 41c458c792..c14807b188 100644
> --- a/hw/can/can_core.c
> +++ b/hw/can/can_core.c
> @@ -34,6 +34,8 @@
>  static QTAILQ_HEAD(, CanBusState) can_buses =
>      QTAILQ_HEAD_INITIALIZER(can_buses);
>  
> +static can_bus_connect_to_host_t can_bus_connect_to_host_fnc;
> +
>  CanBusState *can_bus_find_by_name(const char *name, bool create_missing)
>  {
>      CanBusState *bus;
> @@ -127,10 +129,15 @@ int can_bus_client_set_filters(CanBusClientState *client,
>  
>  int can_bus_connect_to_host_device(CanBusState *bus, const char *name)
>  {
> -    if (can_bus_connect_to_host_variant == NULL) {
> +    if (can_bus_connect_to_host_fnc == NULL) {
>          error_report("CAN bus connect to host device is not "
>                       "supported on this system");
>          exit(1);
>      }
> -    return can_bus_connect_to_host_variant(bus, name);
> +    return can_bus_connect_to_host_fnc(bus, name);
> +}
> +
> +void can_bus_set_connect_to_host(can_bus_connect_to_host_t connect_fnc)
> +{
> +    can_bus_connect_to_host_fnc = connect_fnc;
>  }
> diff --git a/hw/can/can_host_stub.c b/hw/can/can_host_stub.c
> deleted file mode 100644
> index 748d25f995..0000000000
> --- a/hw/can/can_host_stub.c
> +++ /dev/null
> @@ -1,36 +0,0 @@
> ....
> ....
> ....
> -
> -
> -int (*can_bus_connect_to_host_variant)(CanBusState *bus, const char *name) =
> -        NULL;
> 
> diff --git a/include/can/can_emu.h b/include/can/can_emu.h
> index 85237ee3c9..7f0705e49f 100644
> --- a/include/can/can_emu.h
> +++ b/include/can/can_emu.h
> @@ -107,8 +107,9 @@ struct CanBusState {
>      QTAILQ_ENTRY(CanBusState) next;
>  };
>  
> -extern int (*can_bus_connect_to_host_variant)(CanBusState *bus,
> -                                              const char *name);
> +typedef int (*can_bus_connect_to_host_t)(CanBusState *bus, const char *name);
> +
> +void can_bus_set_connect_to_host(can_bus_connect_to_host_t connect_fnc);
>  
>  int can_bus_filter_match(struct qemu_can_filter *filter, qemu_canid_t can_id);
> ----------------------------------------------------------------
> 
> Best wishes,
> 
> Pavel
> 

  reply	other threads:[~2018-01-24 21:41 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-14 20:14 [Qemu-devel] [PATCH V4 0/7] CAN bus support for QEMU (SJA1000 PCI so far) pisa
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 1/7] CAN bus simple messages transport implementation for QEMU pisa
2018-01-19 12:38   ` Philippe Mathieu-Daudé
2018-01-19 13:28     ` Pavel Pisa
2018-01-19 17:04     ` Pavel Pisa
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 2/7] CAN bus support to connect bust to Linux host SocketCAN interface pisa
2018-01-15  2:55   ` Philippe Mathieu-Daudé
2018-01-15 21:29     ` Pavel Pisa
2018-01-16  0:12       ` Philippe Mathieu-Daudé
2018-01-19  8:51         ` Pavel Pisa
2018-01-19 13:37           ` Philippe Mathieu-Daudé
2018-01-22 10:28             ` Stefan Hajnoczi
2018-01-19 13:37         ` Daniel P. Berrange
2018-01-19 12:57   ` Philippe Mathieu-Daudé
2018-01-19 13:01     ` Philippe Mathieu-Daudé
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 3/7] CAN bus SJA1000 chip register level emulation for QEMU pisa
2018-01-15  3:03   ` Philippe Mathieu-Daudé
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 4/7] CAN bus Kvaser PCI CAN-S (single SJA1000 channel) emulation added pisa
2018-01-15  3:09   ` Philippe Mathieu-Daudé
2018-03-06 15:29   ` Thomas Huth
2018-03-06 20:52     ` Pavel Pisa
2018-03-07 11:40       ` Paolo Bonzini
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 5/7] QEMU CAN bus emulation documentation pisa
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 6/7] CAN bus PCM-3680I PCI (dual SJA1000 channel) emulation added pisa
2018-01-15  3:12   ` Philippe Mathieu-Daudé
2018-01-19 13:15   ` Philippe Mathieu-Daudé
2018-01-14 20:14 ` [Qemu-devel] [PATCH V4 7/7] CAN bus MIOe-3680 " pisa
2018-01-19 13:13   ` Philippe Mathieu-Daudé
2018-01-22 11:35 ` [Qemu-devel] [PATCH V4 0/7] CAN bus support for QEMU (SJA1000 PCI so far) Philippe Mathieu-Daudé
2018-01-23 21:42   ` Pavel Pisa
2018-01-24 20:22     ` Pavel Pisa
2018-01-24 21:41       ` Philippe Mathieu-Daudé [this message]
2018-01-25  8:24         ` Pavel Pisa
2018-01-25 13:50           ` Deniz Eren
2018-01-25 13:58     ` Paolo Bonzini
2018-01-25 21:33       ` Pavel Pisa
2018-01-26 11:12         ` Paolo Bonzini
2018-01-28  9:02           ` Pavel Pisa
2018-01-29  7:43             ` Oleksij Rempel
2018-01-30 14:15         ` Paolo Bonzini
2018-01-30 22:12           ` Pavel Pisa
2018-01-31  0:13             ` Deniz Eren
2018-01-31  1:08               ` Paolo Bonzini
2018-01-31  1:10                 ` Paolo Bonzini
2018-01-31  4:07 Deniz Eren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=abe89c1b-b6fa-3021-fad1-469d2eb2060a@amsat.org \
    --to=f4bug@amsat.org \
    --cc=deniz.eren@icloud.com \
    --cc=frederic.konrad@adacore.com \
    --cc=jan.kiszka@siemens.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=marex@denx.de \
    --cc=o.rempel@pengutronix.de \
    --cc=pbonzini@redhat.com \
    --cc=pisa@cmp.felk.cvut.cz \
    --cc=qemu-devel@nongnu.org \
    --cc=socketcan@hartkopp.net \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.