qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Implementing new serial virtual HW w/ redirection


From: Markus Armbruster
Subject: Re: [Qemu-devel] Implementing new serial virtual HW w/ redirection
Date: Tue, 21 Feb 2012 07:58:16 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Emmanuel Blot <address@hidden> writes:

> Hi All,
>
> I'm new to the ML.
>
> I've started to port Qemu to a new HW based on ARM926EJ-S core.
> So far so good, I've implemented some basic HW (INT controller, System
> register, UART, …)
>
> I'd like to redirect the virtual serial port not to the current
> default stdin/stdout of the Qemu
> application, but to a (Unix) socket.
> I'm not sure I'm looking at the proper solution, so any advice is welcomed.
>
> AFAIU, I may define a Unix socket with the command line:
> -chardev socket,id=sersok,path=~user/serialsocket,server,nowait
>
> and assign the new virtual serial device (named new-uart hereafter):
> -device new-uart,chardev=sersock
>
> Is it the proper way to map the new virtual UART to the Unix socket?

Yes, this is the qdev way.  It's being replaced by QOM, but I can't say
how that'll affect you.

> My main question is about the driver implementation:
> For the first implementation, I simply used
>  * qdev_init_chardev
>  * qemu_chr_add_handlers
>  * qemu_chr_fe_write
> calls to implement the virtual serial port. It works fine to print out
> and read from the standard I/O, but I'm not sure to understand what I should
> implement to use the chardev created from the command line rather than the
> default standard I/O.
>
> qdev_init_chardev() seems somewhat deprecated, as the implementation
> contains the following comment:
>     /* FIXME: This function needs to go away: use chardev properties!  */

Since renamed to qemu_char_get_next_serial().

> Should I drop qdev_init_chardev() for another API?
>
> I've looked at several examples on virtual serial port in existing Qemu 
> drivers,
> but I don't know what is the best and simplest way to go.

Have a look at hw/serial.c.

    static Property serial_isa_properties[] = {
        DEFINE_PROP_UINT32("index", ISASerialState, index,   -1),
        DEFINE_PROP_HEX32("iobase", ISASerialState, iobase,  -1),
        DEFINE_PROP_UINT32("irq",   ISASerialState, isairq,  -1),
--->    DEFINE_PROP_CHR("chardev",  ISASerialState, state.chr),
        DEFINE_PROP_END_OF_LIST(),
    };

Defines property "chardev" for "-device new-uart,chardev=sersock".
Check out how the code uses ISASerialState member state.chr.  In
particular:

    static void serial_init_core(SerialState *s)
    {
        if (!s->chr) {
            fprintf(stderr, "Can't create serial device, empty char device\n");
            exit(1);
        }

[..]
        qemu_chr_add_handlers(s->chr, serial_can_receive1, serial_receive1,
                              serial_event, s);
    }

There's also the old -serial option, which is still handled by the board
initialization function.  Here's pc_basic_device_init():

        for(i = 0; i < MAX_SERIAL_PORTS; i++) {
            if (serial_hds[i]) {
                serial_isa_init(isa_bus, i, serial_hds[i]);
            }
        }

docs/qdev-device-use.txt explains how -serial and -device are related.

> Any advice would be greatly appreciated,

Hope this helps.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]