s390: channel I/O support in qemu.
v6 cover s390: channel I/O support in qemu.
Hi,
another round for virtual channel I/O in qemu.
The patches have been respun against current master; changelogs are in the patches themselves.
Changes are mostly some cleanups; of note are the preparations for VirtioBus and some changes for making the code endianness aware.
Making s390-ccw-virtio the default machine has been deferred until after tcg support is available.
Alexander Graf (1):
s390: Add default support for SCLP console
Cornelia Huck (10):
s390: Lowcore mapping helper.
s390: Add mapping helper functions.
s390: Channel I/O basic definitions.
s390: I/O interrupt and machine check injection.
s390: Add channel I/O instructions.
s390: Virtual channel subsystem support.
s390: Wire up channel I/O in kvm.
s390: Add new channel I/O based virtio transport.
s390-virtio: Factor out some initialization code.
s390: Add s390-ccw-virtio machine.
hw/boards.h | 1 + hw/s390-virtio.c | 118 ++-- hw/s390-virtio.h | 6 + hw/s390x/Makefile.objs | 3 + hw/s390x/css.c | 1277 ++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/css.h | 99 ++++ hw/s390x/s390-virtio-ccw.c | 134 +++++ hw/s390x/virtio-ccw.c | 947 ++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 94 ++++ target-s390x/Makefile.objs | 2 +- target-s390x/cpu.h | 247 ++++++++- target-s390x/helper.c | 200 ++++++- target-s390x/ioinst.c | 752 ++++++++++++++++++++++++++ target-s390x/ioinst.h | 223 ++++++++ target-s390x/kvm.c | 239 ++++++++- trace-events | 18 + vl.c | 48 ++ 17 files changed, 4333 insertions(+), 75 deletions(-) create mode 100644 hw/s390x/css.c create mode 100644 hw/s390x/css.h create mode 100644 hw/s390x/s390-virtio-ccw.c create mode 100644 hw/s390x/virtio-ccw.c create mode 100644 hw/s390x/virtio-ccw.h create mode 100644 target-s390x/ioinst.c create mode 100644 target-s390x/ioinst.h
Signature · 1 line
1.7.12.4
PATCH v6 1/11 s390: Lowcore mapping helper.
Create a lowcore mapping helper that includes a check for sufficient length.
---
v5 -> v6:
- Check returned len of cpu_physical_memory_map
- Don't pass lowcore len
--- target-s390x/helper.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
target-s390x/helper.c +25 -9
@@ -471,13 +471,31 @@ static uint64_t get_psw_mask(CPUS390XState *env)return r; } +static LowCore *cpu_map_lowcore (CPUS390XState *env) +{ +LowCore *lowcore; +hwaddr len =sizeof (LowCore); + + lowcore =cpu_physical_memory_map (env->psa, &len,1 ); + +if (len <sizeof (LowCore)) { +cpu_abort (env,"Could not map lowcore\n" ); + } + +return lowcore; +} + +static void cpu_unmap_lowcore (LowCore *lowcore) +{ +cpu_physical_memory_unmap (lowcore,sizeof (LowCore),1 ,sizeof (LowCore)); +} +static void do_svc_interrupt (CPUS390XState *env) {uint64_t mask, addr;LowCore *lowcore; -hwaddr len =TARGET_PAGE_SIZE ; - lowcore =cpu_physical_memory_map (env->psa, &len,1 ); + lowcore =cpu_map_lowcore (env); lowcore->svc_code =cpu_to_be16 (env->int_svc_code); lowcore->svc_ilen =cpu_to_be16 (env->int_svc_ilen);
@@ -486,7 +504,7 @@ static void do_svc_interrupt(CPUS390XState *env) mask =be64_to_cpu (lowcore->svc_new_psw.mask); addr =be64_to_cpu (lowcore->svc_new_psw.addr); -cpu_physical_memory_unmap (lowcore, len,1 , len); +cpu_unmap_lowcore (lowcore);load_psw (env, mask, addr); }
@@ -495,7 +513,6 @@ static void do_program_interrupt(CPUS390XState *env) {uint64_t mask, addr;LowCore *lowcore; -hwaddr len =TARGET_PAGE_SIZE ;int ilen = env->int_pgm_ilen;switch (ilen) {
@@ -513,7 +530,7 @@ static void do_program_interrupt(CPUS390XState *env)qemu_log_mask (CPU_LOG_INT ,"%s: code=0x%x ilen=%d\n" , __func__, env->int_pgm_code, ilen); - lowcore =cpu_physical_memory_map (env->psa, &len,1 ); + lowcore =cpu_map_lowcore (env); lowcore->pgm_ilen =cpu_to_be16 (ilen); lowcore->pgm_code =cpu_to_be16 (env->int_pgm_code);
@@ -522,7 +539,7 @@ static void do_program_interrupt(CPUS390XState *env) mask =be64_to_cpu (lowcore->program_new_psw.mask); addr =be64_to_cpu (lowcore->program_new_psw.addr); -cpu_physical_memory_unmap (lowcore, len,1 , len); +cpu_unmap_lowcore (lowcore); DPRINTF("%s: %x %x %" PRIx64 " %" PRIx64 "\n", __func__, env->int_pgm_code, ilen, env->psw.mask,
@@ -537,7 +554,6 @@ static void do_ext_interrupt(CPUS390XState *env) {uint64_t mask, addr;LowCore *lowcore; -hwaddr len =TARGET_PAGE_SIZE ;ExtQueue *q;if (!(env->psw.mask &PSW_MASK_EXT )) {
@@ -549,7 +565,7 @@ static void do_ext_interrupt(CPUS390XState *env) } q = &env->ext_queue[env->ext_index]; - lowcore =cpu_physical_memory_map (env->psa, &len,1 ); + lowcore =cpu_map_lowcore (env); lowcore->ext_int_code =cpu_to_be16 (q->code); lowcore->ext_params =cpu_to_be32 (q->param);
@@ -560,7 +576,7 @@ static void do_ext_interrupt(CPUS390XState *env) mask =be64_to_cpu (lowcore->external_new_psw.mask); addr =be64_to_cpu (lowcore->external_new_psw.addr); -cpu_physical_memory_unmap (lowcore, len,1 , len); +cpu_unmap_lowcore (lowcore); env->ext_index--;if (env->ext_index ==-1 ) {
Signature · 1 line
1.7.12.4
PATCH v6 2/11 s390: Add mapping helper functions.
In reply to Cornelia HuckAdd s390_cpu_physical_memory_{map,unmap} with special handling for the lowcore.
---
v5 -> v6:
- Make lowcore/0 page handling easier to read
- Make len a pointer
--- target-s390x/cpu.h | 4 ++++ target-s390x/helper.c | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+)
target-s390x/cpu.h +4 -0
@@ -302,6 +302,10 @@ int cpu_s390x_handle_mmu_fault (CPUS390XState *env, target_ulong address, int rw#ifndef CONFIG_USER_ONLY +void *s390_cpu_physical_memory_map (CPUS390XState *env,hwaddr addr,hwaddr *len, +int is_write); +void s390_cpu_physical_memory_unmap (CPUS390XState *env,void *addr,hwaddr len, +int is_write);void s390x_tod_timer (void *opaque);void s390x_cpu_timer (void *opaque);
target-s390x/helper.c +25 -0
@@ -490,6 +490,31 @@ static void cpu_unmap_lowcore(LowCore *lowcore)cpu_physical_memory_unmap (lowcore,sizeof (LowCore),1 ,sizeof (LowCore)); } +void *s390_cpu_physical_memory_map (CPUS390XState *env,hwaddr addr,hwaddr *len, +int is_write) +{ +hwaddr start = addr; + +/* Mind the prefix area. */ +if (addr <8192 ) { +/* Map the lowcore. */ + start += env->psa; + *len =MIN (*len,8192 - addr); + }else if ((addr >= env->psa) && (addr < env->psa +8192 )) { +/* Map the 0 page. */ + start -= env->psa; + *len =MIN (*len,8192 - start); + } + +return cpu_physical_memory_map (start, len, is_write); +} + +void s390_cpu_physical_memory_unmap (CPUS390XState *env,void *addr,hwaddr len, +int is_write) +{ +cpu_physical_memory_unmap (addr, len, is_write, len); +} +static void do_svc_interrupt (CPUS390XState *env) {uint64_t mask, addr;
Signature · 1 line
1.7.12.4
PATCH v6 3/11 s390: Channel I/O basic definitions.
In reply to Cornelia HuckBasic channel I/O structures and helper function.
---
v5 -> v6:
- Move typedefs into ioinst.h and include ioinst.h in cpu.h instead
--- target-s390x/Makefile.objs | 2 +- target-s390x/cpu.h | 1 + target-s390x/ioinst.c | 36 ++++++++ target-s390x/ioinst.h | 207 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 target-s390x/ioinst.c create mode 100644 target-s390x/ioinst.h
target-s390x/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ obj-y += translate.o helper.o cpu.o interrupt.o obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o -obj-$(CONFIG_SOFTMMU) += machine.o +obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o obj-$(CONFIG_KVM) += kvm.o
target-s390x/cpu.h +1 -0
@@ -300,6 +300,7 @@ int cpu_s390x_handle_mmu_fault (CPUS390XState *env, target_ulong address, int rw int mmu_idx);#define cpu_handle_mmu_fault cpu_s390x_handle_mmu_fault +#include "ioinst.h" #ifndef CONFIG_USER_ONLY void *s390_cpu_physical_memory_map(CPUS390XState *env, hwaddr addr, hwaddr *len,
target-s390x/ioinst.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* I/O instructions for S/390 +* +* Copyright 2012 IBM Corp. +* Author(s): Cornelia Huck <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ + +#include <sys/types.h> + +#include "cpu.h" +#include "ioinst.h" + +int ioinst_disassemble_sch_ident (uint32_t value,int *m,int *cssid,int *ssid, +int *schid) +{ +if (!IOINST_SCHID_ONE (value)) { +return -EINVAL ; + } +if (!IOINST_SCHID_M (value)) { +if (IOINST_SCHID_CSSID (value)) { +return -EINVAL ; + } + *cssid =0 ; + *m =0 ; + }else { + *cssid =IOINST_SCHID_CSSID (value); + *m =1 ; + } + *ssid =IOINST_SCHID_SSID (value); + *schid =IOINST_SCHID_NR (value); +return 0 ; +}
target-s390x/ioinst.h new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
1.7.12.4
PATCH v6 4/11 s390: I/O interrupt and machine check injection.
In reply to Cornelia HuckI/O interrupts are queued per isc. Only crw pending machine checks are supported.
---
v5 -> v6:
- Adapt to cpu_map_lowcore changes
--- target-s390x/cpu.h | 69 +++++++++++++++++++++++- target-s390x/helper.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+), 1 deletion(-)
target-s390x/cpu.h +68 -1
@@ -50,6 +50,11 @@#define MMU_USER_IDX 1#define MAX_EXT_QUEUE 16 +#define MAX_IO_QUEUE 16 +#define MAX_MCHK_QUEUE 16 + +#define PSW_MCHK_MASK 0x0004000000000000 +#define PSW_IO_MASK 0x0200000000000000 typedef struct PSW { uint64_t mask;
@@ -62,6 +67,17 @@ typedef struct ExtQueue {uint32_t param64; } ExtQueue; +typedef struct IOIntQueue { +uint16_t id; +uint16_t nr; +uint32_t parm; +uint32_t word; +}IOIntQueue ; + +typedef struct MchkQueue { +uint16_t type; +}MchkQueue ; + typedef struct CPUS390XState { uint64_t regs[16]; /* GP registers */ CPU_DoubleU fregs[16]; /* FP registers */
@@ -93,9 +109,17 @@ typedef struct CPUS390XState {uint64_t cregs[16 ];/* control registers */ ExtQueue ext_queue[MAX_EXT_QUEUE ]; -int pending_int; +IOIntQueue io_queue[MAX_IO_QUEUE ][8 ]; +MchkQueue mchk_queue[MAX_MCHK_QUEUE ]; +int pending_int;int ext_index; +int io_index[8 ]; +int mchk_index; + +uint64_t ckc; +uint64_t cputm; +uint32_t todpr;CPU_COMMON
@@ -375,10 +399,14 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);#define EXCP_EXT 1/* external interrupt */ #define EXCP_SVC 2/* supervisor call (syscall) */ #define EXCP_PGM 3/* program interruption */ +#define EXCP_IO 7/* I/O interrupt */ +#define EXCP_MCHK 8/* machine check */ #define INTERRUPT_EXT (1 << 0)#define INTERRUPT_TOD (1 << 1)#define INTERRUPT_CPUTIMER (1 << 2) +#define INTERRUPT_IO (1 << 3) +#define INTERRUPT_MCHK (1 << 4)/* Program Status Word. */ #define S390_PSWM_REGNUM 0
@@ -841,6 +869,45 @@ static inline void cpu_inject_ext(CPUS390XState *env, uint32_t code, uint32_t pacpu_interrupt (env,CPU_INTERRUPT_HARD ); } +static inline void cpu_inject_io (CPUS390XState *env,uint16_t subchannel_id, +uint16_t subchannel_number, +uint32_t io_int_parm,uint32_t io_int_word) +{ +int isc =ffs (io_int_word <<2 ) -1 ; + +if (env->io_index[isc] ==MAX_IO_QUEUE -1 ) { +/* ugh - can't queue anymore. Let's drop. */ +return ; + } + + env->io_index[isc]++; +assert (env->io_index[isc] <MAX_IO_QUEUE ); + + env->io_queue[env->io_index[isc]][isc].id = subchannel_id; + env->io_queue[env->io_index[isc]][isc].nr = subchannel_number; + env->io_queue[env->io_index[isc]][isc].parm = io_int_parm; + env->io_queue[env->io_index[isc]][isc].word = io_int_word; + + env->pending_int |=INTERRUPT_IO ; +cpu_interrupt (env,CPU_INTERRUPT_HARD ); +} + +static inline void cpu_inject_crw_mchk (CPUS390XState *env) +{ +if (env->mchk_index ==MAX_MCHK_QUEUE -1 ) { +/* ugh - can't queue anymore. Let's drop. */ +return ; + } + + env->mchk_index++; +assert (env->mchk_index <MAX_MCHK_QUEUE ); + + env->mchk_queue[env->mchk_index].type =1 ; + + env->pending_int |=INTERRUPT_MCHK ; +cpu_interrupt (env,CPU_INTERRUPT_HARD ); +} +static inline bool cpu_has_work (CPUState *cpu) {CPUS390XState *env = &S390_CPU (cpu)->env;
target-s390x/helper.c +141 -0
165 lines not on this page · raw message
Signature · 1 line
1.7.12.4
PATCH v6 5/11 s390: Add channel I/O instructions.
In reply to Cornelia HuckProvide handlers for (most) channel I/O instructions.
---
v5 -> v6:
- Adapt to s390_cpu_physical_memory_map changes
- Simplify chsc handling
- Handle endianness
--- target-s390x/cpu.h | 100 +++++++ target-s390x/ioinst.c | 716 ++++++++++++++++++++++++++++++++++++++++++++++++++ target-s390x/ioinst.h | 16 ++ trace-events | 6 + 4 files changed, 838 insertions(+)
target-s390x/cpu.h +100 -0
@@ -147,6 +147,9 @@ static inline void cpu_clone_regs(CPUS390XState *env, target_ulong newsp) }#endif +/* distinguish between 24 bit and 31 bit addressing */ +#define HIGH_ORDER_BIT 0x80000000 +/* Interrupt Codes */ /* Program Interrupts */ #define PGM_OPERATION 0x0001
@@ -331,6 +334,20 @@ void *s390_cpu_physical_memory_map(CPUS390XState *env, hwaddr addr, hwaddr *len, int is_write);void s390_cpu_physical_memory_unmap (CPUS390XState *env,void *addr,hwaddr len,int is_write); +static inline hwaddr decode_basedisp_s (CPUS390XState *env,uint32_t ipb) +{ +hwaddr addr =0 ; +uint8_t reg; + + reg = ipb >>28 ; +if (reg >0 ) { + addr = env->regs[reg]; + } + addr += (ipb >>16 ) &0xfff ; + +return addr; +} +void s390x_tod_timer (void *opaque);void s390x_cpu_timer (void *opaque);
@@ -380,6 +397,89 @@ static inline unsigned s390_del_running_cpu(CPUS390XState *env)void cpu_lock (void );void cpu_unlock (void ); +typedef struct SubchDev SubchDev ; + +static inline SubchDev *css_find_subch (uint8_t m,uint8_t cssid,uint8_t ssid, +uint16_t schid) +{ +return NULL ; +} +static inline bool css_subch_visible (SubchDev *sch) +{ +return false; +} +static inline void css_conditional_io_interrupt (SubchDev *sch) +{ +} +static inline int css_do_stsch (SubchDev *sch,SCHIB *schib) +{ +return -ENODEV ; +} +static inline bool css_schid_final (uint8_t cssid,uint8_t ssid,uint16_t schid) +{ +return true; +} +static inline int css_do_msch (SubchDev *sch,SCHIB *schib) +{ +return -ENODEV ; +} +static inline int css_do_xsch (SubchDev *sch) +{ +return -ENODEV ; +} +static inline int css_do_csch (SubchDev *sch) +{ +return -ENODEV ; +} +static inline int css_do_hsch (SubchDev *sch) +{ +return -ENODEV ; +} +static inline int css_do_ssch (SubchDev *sch,ORB *orb) +{ +return -ENODEV ; +} +static inline int css_do_tsch (SubchDev *sch,IRB *irb) +{ +return -ENODEV ; +} +static inline int css_do_stcrw (CRW *crw) +{ +return 1 ; +} +static inline int css_do_tpi (uint64_t addr,int lowcore) +{ +return 0 ; +} +static inline int css_collect_chp_desc (int m,uint8_t cssid,uint8_t f_chpid, +int rfmt,uint8_t l_chpid,void *buf) +{ +return 0 ; +} +static inline void css_do_schm (uint8_t mbk,int update,int dct,uint64_t mbo) +{ +} +static inline int css_enable_mss (void ) +{ +return -EINVAL ; +} +static inline int css_enable_mcsse (void ) +{ +return -EINVAL ; +} +static inline int css_do_rsch (SubchDev *sch) +{ +return -ENODEV ; +} +static inline int css_do_rchp (uint8_t cssid,uint8_t chpid) +{ +return -ENODEV ; +} +static inline bool css_present (uint8_t cssid) +{ +return false; +} +static inline void cpu_set_tls (CPUS390XState *env,target_ulong newtls) { env->aregs[0 ] = newtls >>32 ;
target-s390x/ioinst.c +716 -0
725 lines not on this page · raw message
target-s390x/ioinst.h +16 -0
@@ -204,4 +204,20 @@ typedef struct CRW {int ioinst_disassemble_sch_ident (uint32_t value,int *m,int *cssid,int *ssid,int *schid); +int ioinst_handle_xsch (CPUS390XState *env,uint64_t reg1); +int ioinst_handle_csch (CPUS390XState *env,uint64_t reg1); +int ioinst_handle_hsch (CPUS390XState *env,uint64_t reg1); +int ioinst_handle_msch (CPUS390XState *env,uint64_t reg1,uint32_t ipb); +int ioinst_handle_ssch (CPUS390XState *env,uint64_t reg1,uint32_t ipb); +int ioinst_handle_stcrw (CPUS390XState *env,uint32_t ipb); +int ioinst_handle_stsch (CPUS390XState *env,uint64_t reg1,uint32_t ipb); +int ioinst_handle_tsch (CPUS390XState *env,uint64_t reg1,uint32_t ipb); +int ioinst_handle_chsc (CPUS390XState *env,uint32_t ipb); +int ioinst_handle_tpi (CPUS390XState *env,uint32_t ipb); +int ioinst_handle_schm (CPUS390XState *env,uint64_t reg1,uint64_t reg2, +uint32_t ipb); +int ioinst_handle_rsch (CPUS390XState *env,uint64_t reg1); +int ioinst_handle_rchp (CPUS390XState *env,uint64_t reg1); +int ioinst_handle_sal (CPUS390XState *env,uint64_t reg1); +#endif
trace-events +6 -0
@@ -1060,3 +1060,9 @@ xics_set_irq_lsi(int srcno, int nr) "set_irq_lsi: srcno %d [irq %#x]" xics_ics_write_xive(int nr, int srcno, int server, uint8_t priority) "ics_write_xive: irq %#x [src %d] server %#x prio %#x" xics_ics_reject(int nr, int srcno) "reject irq %#x [src %d]" xics_ics_eoi(int nr) "ics_eoi: irq %#x" + +# target-s390x/ioinst.c +ioinst(const char *insn) "IOINST: %s" +ioinst_sch_id(const char *insn, int cssid, int ssid, int schid) "IOINST: %s (%x.%x.%04x)" +ioinst_chp_id(const char *insn, int cssid, int chpid) "IOINST: %s (%x.%02x)" +ioinst_chsc_cmd(uint16_t cmd, uint16_t len) "IOINST: chsc command %04x, len %04x"
Signature · 1 line
1.7.12.4
PATCH v6 6/11 s390: Virtual channel subsystem support.
In reply to Cornelia HuckProvide a mechanism for qemu to provide fully virtual subchannels to the guest.
---
v5 -> v6:
- Remove extraneous NULL pointer checks
- Use helper function to build subchannel id
- Endianness
- Get rid of qemu_get_ram_ptr
- Move kvm_enabled() check into generic code
- Define CIWs properly
--- hw/s390x/Makefile.objs | 1 + hw/s390x/css.c | 1277 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/css.h | 99 ++++ target-s390x/cpu.h | 62 +++ trace-events | 8 + 5 files changed, 1447 insertions(+) create mode 100644 hw/s390x/css.c create mode 100644 hw/s390x/css.h
hw/s390x/Makefile.objs +1 -0
@@ -6,3 +6,4 @@ obj-y += sclp.o obj-y += event-facility.o obj-y += sclpquiesce.o sclpconsole.o obj-y += ipl.o +obj-y += css.o
hw/s390x/css.c new file +1277 -0
1,277 lines not on this page · raw message
hw/s390x/css.h new file +99 -0
99 lines not on this page · raw message
target-s390x/cpu.h +62 -0
78 lines not on this page · raw message
trace-events +8 -0
@@ -1066,3 +1066,11 @@ ioinst(const char *insn) "IOINST: %s" ioinst_sch_id(const char *insn, int cssid, int ssid, int schid) "IOINST: %s (%x.%x.%04x)" ioinst_chp_id(const char *insn, int cssid, int chpid) "IOINST: %s (%x.%02x)" ioinst_chsc_cmd(uint16_t cmd, uint16_t len) "IOINST: chsc command %04x, len %04x" + +# hw/s390x/css.c +css_enable_facility(const char *facility) "CSS: enable %s" +css_crw(uint8_t rsc, uint8_t erc, uint16_t rsid, const char *chained) "CSS: queueing crw: rsc=%x, erc=%x, rsid=%x %s" +css_chpid_add(uint8_t cssid, uint8_t chpid, uint8_t type) "CSS: add chpid %x.%02x (type %02x)" +css_new_image(uint8_t cssid, const char *default_cssid) "CSS: add css image %02x %s" +css_assign_subch(const char *do_assign, uint8_t cssid, uint8_t ssid, uint16_t schid, uint16_t devno) "CSS: %s %x.%x.%04x (devno %04x)" +css_io_interrupt(int cssid, int ssid, int schid, uint32_t intparm, uint8_t isc, const char *conditional) "CSS: I/O interrupt on sch %x.%x.%04x (intparm %08x, isc %x) %s"
Signature · 1 line
1.7.12.4
PATCH v6 7/11 s390: Wire up channel I/O in kvm.
In reply to Cornelia HuckTrigger the code for our virtual css in case of instruction intercepts for I/O instructions.
Handle the tsch exit for the subchannel-related part of tsch.
--- target-s390x/cpu.h | 11 +++ target-s390x/kvm.c | 239 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 237 insertions(+), 13 deletions(-)
target-s390x/cpu.h +11 -0
@@ -1058,6 +1058,13 @@ void QEMU_NORETURN runtime_exception(CPUS390XState *env, int excp,#include <sysemu/kvm.h> +#ifdef CONFIG_KVM +void kvm_s390_io_interrupt (S390CPU *cpu,uint16_t subchannel_id, +uint16_t subchannel_nr,uint32_t io_int_parm, +uint32_t io_int_word); +void kvm_s390_crw_mchk (S390CPU *cpu); +void kvm_s390_enable_css_support (S390CPU *cpu); +#else static inline void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, uint16_t subchannel_nr,
@@ -1068,6 +1075,10 @@ static inline void kvm_s390_io_interrupt(S390CPU *cpu,static inline void kvm_s390_crw_mchk (S390CPU *cpu) { } +static inline void kvm_s390_enable_css_support (S390CPU *cpu) +{ +} +#endif static inline void s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,
target-s390x/kvm.c +226 -13
283 lines not on this page · raw message
Signature · 1 line
1.7.12.4
PATCH v6 8/11 s390: Add new channel I/O based virtio transport.
In reply to Cornelia HuckAdd a new virtio transport that uses channel commands to perform virtio operations.
---
v5 -> v6:
- Get rid of qemu_get_ram_ptr usage
- Adapt to virtual css changes
- Constify TypeInfos
- Prepare for VirtioBus
--- hw/s390x/Makefile.objs | 1 + hw/s390x/virtio-ccw.c | 947 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 94 +++++ trace-events | 4 + 4 files changed, 1046 insertions(+) create mode 100644 hw/s390x/virtio-ccw.c create mode 100644 hw/s390x/virtio-ccw.h
hw/s390x/Makefile.objs +1 -0
@@ -7,3 +7,4 @@ obj-y += event-facility.o obj-y += sclpquiesce.o sclpconsole.o obj-y += ipl.o obj-y += css.o +obj-y += virtio-ccw.o
hw/s390x/virtio-ccw.c new file +947 -0
947 lines not on this page · raw message
hw/s390x/virtio-ccw.h new file +94 -0
94 lines not on this page · raw message
trace-events +4 -0
@@ -1074,3 +1074,7 @@ css_chpid_add(uint8_t cssid, uint8_t chpid, uint8_t type) "CSS: add chpid %x.%02 css_new_image(uint8_t cssid, const char *default_cssid) "CSS: add css image %02x %s" css_assign_subch(const char *do_assign, uint8_t cssid, uint8_t ssid, uint16_t schid, uint16_t devno) "CSS: %s %x.%x.%04x (devno %04x)" css_io_interrupt(int cssid, int ssid, int schid, uint32_t intparm, uint8_t isc, const char *conditional) "CSS: I/O interrupt on sch %x.%x.%04x (intparm %08x, isc %x) %s" + +# hw/s390x/virtio-ccw.c +virtio_ccw_interpret_ccw(int cssid, int ssid, int schid, int cmd_code) "VIRTIO-CCW: %x.%x.%04x: interpret command %x" +virtio_ccw_new_device(int cssid, int ssid, int schid, int devno, const char *devno_mode) "VIRTIO-CCW: add subchannel %x.%x.%04x, devno %04x (%s)"
Signature · 1 line
1.7.12.4
PATCH v6 9/11 s390-virtio: Factor out some initialization code.
In reply to Cornelia HuckSome of the machine initialization for s390-virtio will be reused by virtio-ccw.
---
v5 -> v6:
- Adapt to ipl device changes
--- hw/s390-virtio.c | 118 +++++++++++++++++++++++++++++++------------------------ hw/s390-virtio.h | 5 +++ 2 files changed, 72 insertions(+), 51 deletions(-)
hw/s390-virtio.c +67 -51
@@ -147,13 +147,73 @@ unsigned s390_del_running_cpu(CPUS390XState *env)return s390_running_cpus; } +void s390_init_ipl_dev (const char *kernel_filename, +const char *kernel_cmdline, +const char *initrd_filename) +{ +DeviceState *dev; + + dev =qdev_create (NULL ,"s390-ipl" ); +if (kernel_filename) { +qdev_prop_set_string (dev,"kernel" , kernel_filename); + } +if (initrd_filename) { +qdev_prop_set_string (dev,"initrd" , initrd_filename); + } +qdev_prop_set_string (dev,"cmdline" , kernel_cmdline); +qdev_init_nofail (dev); +} + +void s390_init_cpus (const char *cpu_model,uint8_t *storage_keys) +{ +int i; + +if (cpu_model ==NULL ) { + cpu_model ="host" ; + } + + ipi_states =g_malloc (sizeof (S390CPU *) * smp_cpus); + +for (i =0 ; i < smp_cpus; i++) { +S390CPU *cpu; + + cpu =cpu_s390x_init (cpu_model); + + ipi_states[i] = cpu; + cpu->env.halted =1 ; + cpu->env.exception_index =EXCP_HLT ; + cpu->env.storage_keys = storage_keys; + } +} + + +void s390_create_virtio_net (BusState *bus,const char *name) +{ +int i; + +for (i =0 ; i < nb_nics; i++) { +NICInfo *nd = &nd_table[i]; +DeviceState *dev; + +if (!nd->model) { + nd->model =g_strdup ("virtio" ); + } + +if (strcmp (nd->model,"virtio" )) { +fprintf (stderr,"S390 only supports VirtIO nics\n" ); +exit (1 ); + } + + dev =qdev_create (bus, name); +qdev_set_nic_properties (dev, nd); +qdev_init_nofail (dev); + } +} +/* PC hardware initialisation */ static void s390_init (QEMUMachineInitArgs *args) {ram_addr_t my_ram_size = args->ram_size; -const char *cpu_model = args->cpu_model; -CPUS390XState *env =NULL ; -DeviceState *dev;MemoryRegion *sysmem =get_system_memory ();MemoryRegion *ram =g_new (MemoryRegion,1 );int shift =0 ;
@@ -161,7 +221,6 @@ static void s390_init(QEMUMachineInitArgs *args)void *virtio_region;hwaddr virtio_region_len;hwaddr virtio_region_start; -int i;/* s390x ram size detection needs a 16bit multiplier + an increment. So guests > 64GB can be specified in 2MB steps etc. */
@@ -176,15 +235,8 @@ static void s390_init(QEMUMachineInitArgs *args)/* get a BUS */ s390_bus =s390_virtio_bus_init (&my_ram_size);s390_sclp_init (); - dev =qdev_create (NULL ,"s390-ipl" ); -if (args->kernel_filename) { -qdev_prop_set_string (dev,"kernel" , args->kernel_filename); - } -if (args->initrd_filename) { -qdev_prop_set_string (dev,"initrd" , args->initrd_filename); - } -qdev_prop_set_string (dev,"cmdline" , args->kernel_cmdline); -qdev_init_nofail (dev); +s390_init_ipl_dev (args->kernel_filename, args->kernel_cmdline, + args->initrd_filename);/* register hypercalls */ s390_virtio_register_hcalls ();
@@ -207,46 +259,10 @@ static void s390_init(QEMUMachineInitArgs *args) storage_keys =g_malloc0 (my_ram_size /TARGET_PAGE_SIZE );/* init CPUs */ -if (cpu_model ==NULL ) { - cpu_model ="host" ; - } - - ipi_states =g_malloc (sizeof (S390CPU *) * smp_cpus); - -for (i =0 ; i < smp_cpus; i++) { -S390CPU *cpu; -CPUS390XState *tmp_env; - - cpu =cpu_s390x_init (cpu_model); - tmp_env = &cpu->env; -if (!env) { - env = tmp_env; - } - ipi_states[i] = cpu; - tmp_env->halted =1 ; - tmp_env->exception_index =EXCP_HLT ; - tmp_env->storage_keys = storage_keys; - } - +s390_init_cpus (args->cpu_model, storage_keys);/* Create VirtIO network adapters */ -for (i =0 ; i < nb_nics; i++) { -NICInfo *nd = &nd_table[i]; -DeviceState *dev; - -if (!nd->model) { - nd->model =g_strdup ("virtio" ); - } - -if (strcmp (nd->model,"virtio" )) { -fprintf (stderr,"S390 only supports VirtIO nics\n" ); -exit (1 ); - } - - dev =qdev_create ((BusState *)s390_bus,"virtio-net-s390" ); -qdev_set_nic_properties (dev, nd); -qdev_init_nofail (dev); - } +s390_create_virtio_net ((BusState *)s390_bus,"virtio-net-s390" ); }static QEMUMachine s390_machine = {
hw/s390-virtio.h +5 -0
@@ -19,4 +19,9 @@typedef int (*s390_virtio_fn )(const uint64_t *args);void s390_register_virtio_hypercall (uint64_t code,s390_virtio_fn fn); +void s390_init_cpus (const char *cpu_model,uint8_t *storage_keys); +void s390_init_ipl_dev (const char *kernel_filename, +const char *kernel_cmdline, +const char *initrd_filename); +void s390_create_virtio_net (BusState *bus,const char *name);#endif
Signature · 1 line
1.7.12.4
PATCH v6 10/11 s390: Add default support for SCLP console
In reply to Cornelia HuckFrom: Alexander Graf <[email protected]>
The current s390 machine uses the virtio console as default console, but this doesn't mean that we always want to keep it that way for new machines.
This patch introduces a way for a machine type to specify that it wants the default console to be an SCLP console, which is a lot closer to what real hardware does.
--- hw/boards.h | 1 + vl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
hw/boards.h +1 -0
@@ -33,6 +33,7 @@ typedef struct QEMUMachine { unsigned int no_serial:1, no_parallel:1, use_virtcon:1, + use_sclp:1, no_floppy:1, no_cdrom:1, no_sdcard:1;
vl.c +48 -0
107 lines not on this page · raw message
Signature · 1 line
1.7.12.4
PATCH v6 11/11 s390: Add s390-ccw-virtio machine.
In reply to Cornelia HuckAdd a new machine type, s390-ccw-virtio, making use of the virtio-ccw transport to present virtio devices as channel devices.
---
v5 -> v6:
- Don't make virtio-ccw the default yet
- Adapt to ipl device changes
- Adapt to VirtioBus changes
- Default to sclp console
--- hw/s390-virtio.h | 1 + hw/s390x/Makefile.objs | 1 + hw/s390x/s390-virtio-ccw.c | 134 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 hw/s390x/s390-virtio-ccw.c
hw/s390-virtio.h +1 -0
@@ -15,6 +15,7 @@#define KVM_S390_VIRTIO_NOTIFY 0#define KVM_S390_VIRTIO_RESET 1#define KVM_S390_VIRTIO_SET_STATUS 2 +#define KVM_S390_VIRTIO_CCW_NOTIFY 3typedef int (*s390_virtio_fn )(const uint64_t *args);void s390_register_virtio_hypercall (uint64_t code,s390_virtio_fn fn);
hw/s390x/Makefile.objs +1 -0
@@ -7,4 +7,5 @@ obj-y += event-facility.o obj-y += sclpquiesce.o sclpconsole.o obj-y += ipl.o obj-y += css.o +obj-y += s390-virtio-ccw.o obj-y += virtio-ccw.o
hw/s390x/s390-virtio-ccw.c new file +134 -0
134 lines not on this page · raw message
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH 08/11] s390: Add new channel I/O based virtio transport.
In reply to Cornelia HuckAm 24.01.2013 13:28, schrieb Cornelia Huck:
Quoted 38 lines
Add a new virtio transport that uses channel commands to perform virtio operations.
Signed-off-by Cornelia Huck <[email protected]>---
v5 -> v6:
- Get rid ofqemu_get_ram_ptrusage
- Adapt to virtual css changes
- Constify TypeInfos
- Prepare for VirtioBus--- hw/s390x/Makefile.objs | 1 + hw/s390x/virtio-ccw.c | 947 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 94 +++++ trace-events | 4 + 4 files changed, 1046 insertions(+) create mode 100644 hw/s390x/virtio-ccw.c create mode 100644 hw/s390x/virtio-ccw.hhw/s390x/Makefile.objs +1
-0@@ -7,3 +7,4 @@ obj-y += event-facility.o obj-y += sclpquiesce.o sclpconsole.o obj-y += ipl.o obj-y += css.o +obj-y += virtio-ccw.ohw/s390x/virtio-ccw.c new file +2
-0@@ -0,0 +1,947 @@ +/* +* virtio ccw target implementation
hw/s390x/virtio-ccw.c line 12
Quoted 10 lines
hw/s390x/virtio-ccw.c new file +10
-0+* +* Copyright 2012 IBM Corp. +* Author(s): Cornelia Huck <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ + +#include <hw/hw.h>
"hw/hw.h"?
Quoted 58 lines
hw/s390x/virtio-ccw.c new file +58
-0+#include "block/block.h" +#include "sysemu/blockdev.h" +#include "sysemu/sysemu.h" +#include "net/net.h" +#include "monitor/monitor.h" +#include "hw/virtio.h" +#include "hw/virtio-serial.h" +#include "hw/virtio-net.h" +#include "hw/sysbus.h" +#include "qemu/bitops.h" +#include "hw/virtio-bus.h" + +#include "ioinst.h" +#include "css.h" +#include "virtio-ccw.h" +#include "trace.h" + +static const TypeInfo virtual_css_bus_info = { + .name =TYPE_VIRTUAL_CSS_BUS , + .parent =TYPE_BUS , + .instance_size =sizeof (VirtualCssBus), +}; + +static const VirtIOBindings virtio_ccw_bindings; + +VirtIODevice *virtio_ccw_get_vdev (SubchDev *sch) +{ +VirtIODevice *vdev =NULL ; + +if (sch->driver_data) { + vdev = ((VirtioCcwData *)sch->driver_data)->vdev; + } +return vdev; +} + +static void virtio_ccw_reset_subchannels (void *opaque) +{ +VirtualCssBus *bus = opaque; +BusChild *kid; +VirtioCcwData *data; +BusState *parent =BUS (bus); + + QTAILQ_FOREACH(kid, &parent->children, sibling) { + data = (VirtioCcwData *)kid->child; +virtio_reset (data->vdev); +css_reset_sch (data->sch); + } +css_reset (); +} + +VirtualCssBus *virtual_css_bus_init (void ) +{ +VirtualCssBus *cbus; +BusState *bus; +DeviceState *dev; + +/* Create bridge device */ + dev =qdev_create (NULL ,"virtual-css-bridge" );
hw/s390x/virtio-ccw.c line 80
Quoted 10 lines
hw/s390x/virtio-ccw.c new file +10
-0+qdev_init_nofail (dev); + +/* Create bus on bridge device */ + bus =qbus_create (TYPE_VIRTUAL_CSS_BUS , dev,"virtual-css" ); + cbus =VIRTUAL_CSS_BUS (bus); + +/* Enable hotplugging */ + bus->allow_hotplug =1 ; + +qemu_register_reset (virtio_ccw_reset_subchannels, cbus);
Can't this be done via BusClass::reset? (requires reordering before TypeInfo / class_init)
Quoted 558 lines
hw/s390x/virtio-ccw.c new file +558
-0+return cbus; +} + +/* Communication blocks used by several channel commands. */ +typedef struct VqInfoBlock { +uint64_t queue; +uint32_t align; +uint16_t index; +uint16_t num; +} QEMU_PACKED VqInfoBlock; + +typedef struct VqConfigBlock { +uint16_t index; +uint16_t num_max; +} QEMU_PACKED VqConfigBlock; + +typedef struct VirtioFeatDesc { +uint32_t features; +uint8_t index; +} QEMU_PACKED VirtioFeatDesc; + +/* Specify where the virtqueues for the subchannel are in guest memory. */ +static int virtio_ccw_set_vqs (SubchDev *sch,uint64_t addr,uint32_t align, +uint16_t index,uint16_t num) +{ +VirtioCcwData *data = sch->driver_data; + +if (index >VIRTIO_PCI_QUEUE_MAX ) { +return -EINVAL ; + } + +/* Current code in virtio.c relies on 4K alignment. */ +if (addr && (align !=4096 )) { +return -EINVAL ; + } + +if (!data) { +return -EINVAL ; + } + +virtio_queue_set_addr (data->vdev, index, addr); +if (!addr) { +virtio_queue_set_vector (data->vdev, index,0 ); + }else { +/* Fail if we don't have a big enough queue. */ +/* TODO: Add interface to handle vring.num changing */ +if (virtio_queue_get_num (data->vdev, index) > num) { +return -EINVAL ; + } +virtio_queue_set_vector (data->vdev, index, index); + } +/* tell notify handler in case of config change */ + data->vdev->config_vector =VIRTIO_PCI_QUEUE_MAX ; +return 0 ; +} + +static int virtio_ccw_cb (SubchDev *sch,CCW1 ccw) +{ +int ret; +VqInfoBlock info; +uint8_t status; +VirtioFeatDesc features; +void *config; +hwaddr indicators; +VqConfigBlock vq_config; +VirtioCcwData *data = sch->driver_data; +bool check_len; +int len; +hwaddr hw_len; + +if (!data) { +return -EINVAL ; + } + +trace_virtio_ccw_interpret_ccw (sch->cssid, sch->ssid, sch->schid, + ccw.cmd_code); + check_len = !((ccw.flags &CCW_FLAG_SLI ) && !(ccw.flags &CCW_FLAG_DC )); + +/* Look at the command. */ +switch (ccw.cmd_code) { +case CCW_CMD_SET_VQ : +if (check_len) { +if (ccw.count !=sizeof (info)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (info)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; + }else { + info.queue =ldq_phys (ccw.cda); + info.align =ldl_phys (ccw.cda +sizeof (info.queue)); + info.index =lduw_phys (ccw.cda +sizeof (info.queue) + +sizeof (info.align)); + info.num =lduw_phys (ccw.cda +sizeof (info.queue) + +sizeof (info.align) + +sizeof (info.index)); + ret =virtio_ccw_set_vqs (sch, info.queue, info.align, info.index, + info.num); + sch->curr_status.scsw.count =0 ; + } +break ; +case CCW_CMD_VDEV_RESET : +virtio_reset (data->vdev); + ret =0 ; +break ; +case CCW_CMD_READ_FEAT : +if (check_len) { +if (ccw.count !=sizeof (features)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (features)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; + }else { + features.index =ldub_phys (ccw.cda +sizeof (features.features)); +if (features.index <ARRAY_SIZE (data->host_features)) { + features.features = data->host_features[features.index]; + }else { +/* Return zeroes if the guest supports more feature bits. */ + features.features =0 ; + } +stl_le_phys (ccw.cda, features.features); + sch->curr_status.scsw.count = ccw.count -sizeof (features); + ret =0 ; + } +break ; +case CCW_CMD_WRITE_FEAT : +if (check_len) { +if (ccw.count !=sizeof (features)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (features)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; + }else { + features.index =ldub_phys (ccw.cda +sizeof (features.features)); + features.features =ldl_le_phys (ccw.cda); +if (features.index <ARRAY_SIZE (data->host_features)) { +if (data->vdev->set_features) { + data->vdev->set_features (data->vdev, features.features); + } + data->vdev->guest_features = features.features; + }else { +/* +* If the guest supports more feature bits, assert that it +* passes us zeroes for those we don't support. +*/ +if (features.features) { +fprintf (stderr,"Guest bug: features[%i]=%x (expected 0)\n" , + features.index, features.features); +/* XXX: do a unit check here? */ + } + } + sch->curr_status.scsw.count = ccw.count -sizeof (features); + ret =0 ; + } +break ; +case CCW_CMD_READ_CONF : +if (check_len) { +if (ccw.count > data->vdev->config_len) { + ret = -EINVAL ; +break ; + } + } + len =MIN (ccw.count, data->vdev->config_len); +if (!ccw.cda) { + ret = -EFAULT ; + }else { + data->vdev->get_config (data->vdev, data->vdev->config); +/* XXX config space endianness */ +cpu_physical_memory_write (ccw.cda, data->vdev->config, len); + sch->curr_status.scsw.count = ccw.count - len; + ret =0 ; + } +break ; +case CCW_CMD_WRITE_CONF : +if (check_len) { +if (ccw.count > data->vdev->config_len) { + ret = -EINVAL ; +break ; + } + } + len =MIN (ccw.count, data->vdev->config_len); + hw_len = len; +if (!ccw.cda) { + ret = -EFAULT ; + }else { + config =cpu_physical_memory_map (ccw.cda, &hw_len,0 ); +if (!config) { + ret = -EFAULT ; + }else { + len = hw_len; +/* XXX config space endianness */ +memcpy (data->vdev->config, config, len); +cpu_physical_memory_unmap (config, hw_len,0 , hw_len); +if (data->vdev->set_config) { + data->vdev->set_config (data->vdev, data->vdev->config); + } + sch->curr_status.scsw.count = ccw.count - len; + ret =0 ; + } + } +break ; +case CCW_CMD_WRITE_STATUS : +if (check_len) { +if (ccw.count !=sizeof (status)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (status)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; + }else { + status =ldub_phys (ccw.cda); +virtio_set_status (data->vdev, status); + sch->curr_status.scsw.count = ccw.count -sizeof (status); + ret =0 ; + } +break ; +case CCW_CMD_SET_IND : +if (check_len) { +if (ccw.count !=sizeof (indicators)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (indicators)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } + indicators =ldq_phys (ccw.cda); +if (!indicators) { + ret = -EFAULT ; + }else { + data->indicators = indicators; + sch->curr_status.scsw.count = ccw.count -sizeof (indicators); + ret =0 ; + } +break ; +case CCW_CMD_SET_CONF_IND : +if (check_len) { +if (ccw.count !=sizeof (indicators)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (indicators)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } + indicators =ldq_phys (ccw.cda); +if (!indicators) { + ret = -EFAULT ; + }else { + data->indicators2 = indicators; + sch->curr_status.scsw.count = ccw.count -sizeof (indicators); + ret =0 ; + } +break ; +case CCW_CMD_READ_VQ_CONF : +if (check_len) { +if (ccw.count !=sizeof (vq_config)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (vq_config)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; + }else { + vq_config.index =lduw_phys (ccw.cda); + vq_config.num_max =virtio_queue_get_num (data->vdev, + vq_config.index); +stw_phys (ccw.cda +sizeof (vq_config.index), vq_config.num_max); + sch->curr_status.scsw.count = ccw.count -sizeof (vq_config); + ret =0 ; + } +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +return ret; +} + +static int virtio_ccw_device_init (VirtioCcwData *dev,VirtIODevice *vdev) +{ +unsigned int cssid =0 ; +unsigned int ssid =0 ; +unsigned int schid; +unsigned int devno; +bool have_devno = false; +bool found = false; +SubchDev *sch; +int ret; +int num; +DeviceState *parent =DEVICE (dev); + + sch =g_malloc0 (sizeof (SubchDev)); + + sch->driver_data = dev; + dev->sch = sch; + + dev->vdev = vdev; + dev->indicators =0 ; + +/* Initialize subchannel structure. */ + sch->channel_prog =0x0 ; + sch->last_cmd_valid = false; + sch->orb =NULL ; +/* +* Use a device number if provided. Otherwise, fall back to subchannel +* number. +*/ +if (dev->bus_id) { + num =sscanf (dev->bus_id,"%x.%x.%04x" , &cssid, &ssid, &devno); +if (num ==3 ) { +if ((cssid >MAX_CSSID ) || (ssid >MAX_SSID )) { + ret = -EINVAL ; +error_report ("Invalid cssid or ssid: cssid %x, ssid %x" , + cssid, ssid); + goto out_err; + } +/* Enforce use of virtual cssid. */ +if (cssid !=VIRTUAL_CSSID ) { + ret = -EINVAL ; +error_report ("cssid %x not valid for virtio devices" , cssid); + goto out_err; + } +if (css_devno_used (cssid, ssid, devno)) { + ret = -EEXIST ; +error_report ("Device %x.%x.%04x already exists" , cssid, ssid, + devno); + goto out_err; + } + sch->cssid = cssid; + sch->ssid = ssid; + sch->devno = devno; + have_devno = true; + }else { + ret = -EINVAL ; +error_report ("Malformed devno parameter '%s'" , dev->bus_id); + goto out_err; + } + } + +/* Find the next free id. */ +if (have_devno) { +for (schid =0 ; schid <=MAX_SCHID ; schid++) { +if (!css_find_subch (1 , cssid, ssid, schid)) { + sch->schid = schid; +css_subch_assign (cssid, ssid, schid, devno, sch); + found = true; +break ; + } + } +if (!found) { + ret = -ENODEV ; +error_report ("No free subchannel found for %x.%x.%04x" , cssid, ssid, + devno); + goto out_err; + } +trace_virtio_ccw_new_device (cssid, ssid, schid, devno, +"user-configured" ); + }else { + cssid =VIRTUAL_CSSID ; +for (ssid =0 ; ssid <=MAX_SSID ; ssid++) { +for (schid =0 ; schid <=MAX_SCHID ; schid++) { +if (!css_find_subch (1 , cssid, ssid, schid)) { + sch->cssid = cssid; + sch->ssid = ssid; + sch->schid = schid; + devno = schid; +/* +* If the devno is already taken, look further in this +* subchannel set. +*/ +while (css_devno_used (cssid, ssid, devno)) { +if (devno ==MAX_SCHID ) { + devno =0 ; + }else if (devno == schid -1 ) { + ret = -ENODEV ; +error_report ("No free devno found" ); + goto out_err; + }else { + devno++; + } + } + sch->devno = devno; +css_subch_assign (cssid, ssid, schid, devno, sch); + found = true; +break ; + } + } +if (found) { +break ; + } + } +if (!found) { + ret = -ENODEV ; +error_report ("Virtual channel subsystem is full!" ); + goto out_err; + } +trace_virtio_ccw_new_device (cssid, ssid, schid, devno, +"auto-configured" ); + } + +/* Build initial schib. */ +css_sch_build_virtual_schib (sch,0 ,VIRTIO_CCW_CHPID_TYPE ); + + sch->ccw_cb = virtio_ccw_cb; + +/* Build senseid data. */ +memset (&sch->id,0 ,sizeof (SenseId)); + sch->id.reserved =0xff ; + sch->id.cu_type =VIRTIO_CCW_CU_TYPE ; + sch->id.cu_model = dev->vdev->device_id; + +virtio_bind_device (vdev, &virtio_ccw_bindings,DEVICE (dev)); +/* Only the first 32 feature bits are used. */ + dev->host_features[0 ] = vdev->get_features (vdev, dev->host_features[0 ]); + dev->host_features[0 ] |=0x1 <<VIRTIO_F_NOTIFY_ON_EMPTY ; + dev->host_features[0 ] |=0x1 <<VIRTIO_F_BAD_FEATURE ; + +css_generate_sch_crws (sch->cssid, sch->ssid, sch->schid, + parent->hotplugged,1 ); +return 0 ; + +out_err: + dev->sch =NULL ; +g_free (sch); +return ret; +} + +static int virtio_ccw_exit (VirtioCcwData *dev) +{ +SubchDev *sch = dev->sch; + +if (sch) { +css_subch_assign (sch->cssid, sch->ssid, sch->schid, sch->devno,NULL ); +g_free (sch); + } + dev->indicators =0 ; +return 0 ; +} + +static int virtio_ccw_net_init (VirtioCcwData *dev) +{ +VirtIODevice *vdev; + + vdev =virtio_net_init ((DeviceState *)dev, &dev->nic, &dev->net); +if (!vdev) { +return -1 ; + } + +return virtio_ccw_device_init (dev, vdev); +} + +static int virtio_ccw_net_exit (VirtioCcwData *dev) +{ +virtio_net_exit (dev->vdev); +return virtio_ccw_exit (dev); +} + +static int virtio_ccw_blk_init (VirtioCcwData *dev) +{ +VirtIODevice *vdev; + + vdev =virtio_blk_init ((DeviceState *)dev, &dev->blk); +if (!vdev) { +return -1 ; + } + +return virtio_ccw_device_init (dev, vdev); +} + +static int virtio_ccw_blk_exit (VirtioCcwData *dev) +{ +virtio_blk_exit (dev->vdev); +blockdev_mark_auto_del (dev->blk.conf.bs); +return virtio_ccw_exit (dev); +} + +static int virtio_ccw_serial_init (VirtioCcwData *dev) +{ +VirtIODevice *vdev; + + vdev =virtio_serial_init ((DeviceState *)dev, &dev->serial); +if (!vdev) { +return -1 ; + } + +return virtio_ccw_device_init (dev, vdev); +} + +static int virtio_ccw_serial_exit (VirtioCcwData *dev) +{ +virtio_serial_exit (dev->vdev); +return virtio_ccw_exit (dev); +} + +static int virtio_ccw_balloon_init (VirtioCcwData *dev) +{ +VirtIODevice *vdev; + + vdev =virtio_balloon_init ((DeviceState *)dev); +if (!vdev) { +return -1 ; + } + +return virtio_ccw_device_init (dev, vdev); +} + +static int virtio_ccw_balloon_exit (VirtioCcwData *dev) +{ +virtio_balloon_exit (dev->vdev); +return virtio_ccw_exit (dev); +} + +static int virtio_ccw_scsi_init (VirtioCcwData *dev) +{ +VirtIODevice *vdev; + + vdev =virtio_scsi_init ((DeviceState *)dev, &dev->scsi); +if (!vdev) { +return -1 ; + } + +return virtio_ccw_device_init (dev, vdev); +} + +static int virtio_ccw_scsi_exit (VirtioCcwData *dev) +{ +virtio_scsi_exit (dev->vdev); +return virtio_ccw_exit (dev); +}
hw/s390x/virtio-ccw.c line 648
Quoted 10 lines
hw/s390x/virtio-ccw.c new file +10
-0+ +/* DeviceState to VirtioCcwData. Note: used on datapath, +* be careful and test performance if you change this. +*/ +static inline VirtioCcwData *to_virtio_ccw_data_fast (DeviceState *d) +{ +return container_of (d, VirtioCcwData, parent_obj); +} + +/* DeviceState to VirtioCcwData. TODO: use QOM. */
Are the prerequisites to resolve this TODO not yet in qemu.git?
Quoted 288 lines
hw/s390x/virtio-ccw.c new file +288
-0+static inline VirtioCcwData *to_virtio_ccw_data (DeviceState *d) +{ +return container_of (d, VirtioCcwData, parent_obj); +} + +static void virtio_ccw_notify (DeviceState *d,uint16_t vector) +{ +VirtioCcwData *dev =to_virtio_ccw_data_fast (d); +SubchDev *sch = dev->sch; +uint64_t indicators; + +if (vector >=128 ) { +return ; + } + +if (vector <VIRTIO_PCI_QUEUE_MAX ) { + indicators =ldq_phys (dev->indicators); +set_bit (vector, &indicators); +stq_phys (dev->indicators, indicators); + }else { + vector =0 ; + indicators =ldq_phys (dev->indicators2); +set_bit (vector, &indicators); +stq_phys (dev->indicators2, indicators); + } + +css_conditional_io_interrupt (sch); + +} + +static unsigned virtio_ccw_get_features (DeviceState *d) +{ +VirtioCcwData *dev =to_virtio_ccw_data (d); + +/* Only the first 32 feature bits are used. */ +return dev->host_features[0 ]; +} + +/**************** Virtio-ccw Bus Device Descriptions *******************/ + +static const VirtIOBindings virtio_ccw_bindings = { + .notify = virtio_ccw_notify, + .get_features = virtio_ccw_get_features, +}; + +static Property virtio_ccw_net_properties[] = { +DEFINE_PROP_STRING ("devno" , VirtioCcwData, bus_id), +DEFINE_VIRTIO_NET_FEATURES (VirtioCcwData, host_features[0 ]), +DEFINE_NIC_PROPERTIES (VirtioCcwData, nic), +DEFINE_PROP_UINT32 ("x-txtimer" , VirtioCcwData, + net.txtimer,TX_TIMER_INTERVAL ), +DEFINE_PROP_INT32 ("x-txburst" , VirtioCcwData, + net.txburst,TX_BURST ), +DEFINE_PROP_STRING ("tx" , VirtioCcwData, net.tx), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_ccw_net_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtIOCCWDeviceClass *k =VIRTIO_CCW_DEVICE_CLASS (klass); + + k->init = virtio_ccw_net_init; + k->exit = virtio_ccw_net_exit; + dc->props = virtio_ccw_net_properties; +} + +static const TypeInfo virtio_ccw_net = { + .name ="virtio-net-ccw" , + .parent =TYPE_VIRTIO_CCW_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_net_class_init, +}; + +static Property virtio_ccw_blk_properties[] = { +DEFINE_PROP_STRING ("devno" , VirtioCcwData, bus_id), +DEFINE_BLOCK_PROPERTIES (VirtioCcwData, blk.conf), +DEFINE_PROP_STRING ("serial" , VirtioCcwData, blk.serial), +#ifdef __linux__ +DEFINE_PROP_BIT ("scsi" , VirtioCcwData, blk.scsi,0 , true), +#endif +DEFINE_VIRTIO_BLK_FEATURES (VirtioCcwData, host_features[0 ]), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_ccw_blk_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtIOCCWDeviceClass *k =VIRTIO_CCW_DEVICE_CLASS (klass); + + k->init = virtio_ccw_blk_init; + k->exit = virtio_ccw_blk_exit; + dc->props = virtio_ccw_blk_properties; +} + +static const TypeInfo virtio_ccw_blk = { + .name ="virtio-blk-ccw" , + .parent =TYPE_VIRTIO_CCW_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_blk_class_init, +}; + +static Property virtio_ccw_serial_properties[] = { +DEFINE_PROP_STRING ("devno" , VirtioCcwData, bus_id), +DEFINE_PROP_UINT32 ("max_ports" , VirtioCcwData, serial.max_virtserial_ports, +31 ), +DEFINE_VIRTIO_COMMON_FEATURES (VirtioCcwData, host_features[0 ]), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_ccw_serial_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtIOCCWDeviceClass *k =VIRTIO_CCW_DEVICE_CLASS (klass); + + k->init = virtio_ccw_serial_init; + k->exit = virtio_ccw_serial_exit; + dc->props = virtio_ccw_serial_properties; +} + +static const TypeInfo virtio_ccw_serial = { + .name ="virtio-serial-ccw" , + .parent =TYPE_VIRTIO_CCW_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_serial_class_init, +}; + +static Property virtio_ccw_balloon_properties[] = { +DEFINE_PROP_STRING ("devno" , VirtioCcwData, bus_id), +DEFINE_VIRTIO_COMMON_FEATURES (VirtioCcwData, host_features[0 ]), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_ccw_balloon_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtIOCCWDeviceClass *k =VIRTIO_CCW_DEVICE_CLASS (klass); + + k->init = virtio_ccw_balloon_init; + k->exit = virtio_ccw_balloon_exit; + dc->props = virtio_ccw_balloon_properties; +} + +static const TypeInfo virtio_ccw_balloon = { + .name ="virtio-balloon-ccw" , + .parent =TYPE_VIRTIO_CCW_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_balloon_class_init, +}; + +static Property virtio_ccw_scsi_properties[] = { +DEFINE_PROP_STRING ("devno" , VirtioCcwData, bus_id), +DEFINE_VIRTIO_SCSI_PROPERTIES (VirtioCcwData, host_features[0 ], scsi), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_ccw_scsi_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtIOCCWDeviceClass *k =VIRTIO_CCW_DEVICE_CLASS (klass); + + k->init = virtio_ccw_scsi_init; + k->exit = virtio_ccw_scsi_exit; + dc->props = virtio_ccw_scsi_properties; +} + +static const TypeInfo virtio_ccw_scsi = { + .name ="virtio-scsi-ccw" , + .parent =TYPE_VIRTIO_CCW_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_scsi_class_init, +}; + +static int virtio_ccw_busdev_init (DeviceState *dev) +{ +VirtioCcwData *_dev = (VirtioCcwData *)dev; +VirtIOCCWDeviceClass *_info =VIRTIO_CCW_DEVICE_GET_CLASS (dev); + +virtio_ccw_bus_new (&_dev->bus, _dev); + +return _info->init (_dev); +} + +static int virtio_ccw_busdev_exit (DeviceState *dev) +{ +VirtioCcwData *_dev = (VirtioCcwData *)dev; +VirtIOCCWDeviceClass *_info =VIRTIO_CCW_DEVICE_GET_CLASS (dev); + +return _info->exit (_dev); +} + +static int virtio_ccw_busdev_unplug (DeviceState *dev) +{ +VirtioCcwData *_dev = (VirtioCcwData *)dev; +SubchDev *sch = _dev->sch; + +/* +* We should arrive here only for device_del, since we don't support +* direct hot(un)plug of channels, but only through virtio. +*/ +assert (sch !=NULL ); +/* Subchannel is now disabled and no longer valid. */ + sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA | +PMCW_FLAGS_MASK_DNV ); + +css_generate_sch_crws (sch->cssid, sch->ssid, sch->schid,1 ,0 ); + +object_unparent (OBJECT (dev)); +qdev_free (dev); +return 0 ; +} + +static void virtio_ccw_device_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->init = virtio_ccw_busdev_init; + dc->exit = virtio_ccw_busdev_exit; + dc->unplug = virtio_ccw_busdev_unplug; + dc->bus_type =TYPE_VIRTUAL_CSS_BUS ; + +} + +static const TypeInfo virtio_ccw_device_info = { + .name =TYPE_VIRTIO_CCW_DEVICE , + .parent =TYPE_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_device_class_init, + .class_size =sizeof (VirtIOCCWDeviceClass), + .abstract = true, +}; + +/***************** Virtual-css Bus Bridge Device ********************/ +/* Only required to have the virtio bus as child in the system bus */ + +static int virtual_css_bridge_init (SysBusDevice *dev) +{ +/* nothing */ +return 0 ; +} + +static void virtual_css_bridge_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); + + k->init = virtual_css_bridge_init; + dc->no_user =1 ; +} + +static const TypeInfo virtual_css_bridge_info = { + .name ="virtual-css-bridge" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (SysBusDevice), + .class_init = virtual_css_bridge_class_init, +}; + +/* virtio-ccw-bus */ + +void virtio_ccw_bus_new (VirtioBusState *bus,VirtioCcwData *dev) +{ +DeviceState *qdev =DEVICE (dev); +BusState *qbus; + +qbus_create_inplace ((BusState *)bus,TYPE_VIRTIO_CCW_BUS , qdev,NULL ); + qbus =BUS (bus); + qbus->allow_hotplug =0 ; +} + +static void virtio_ccw_bus_class_init (ObjectClass *klass,void *data) +{ +VirtioBusClass *k =VIRTIO_BUS_CLASS (klass); +BusClass *bus_class =BUS_CLASS (klass); + + bus_class->max_dev =1 ; + k->notify = virtio_ccw_notify; + k->get_features = virtio_ccw_get_features; +} + +static const TypeInfo virtio_ccw_bus_info = { + .name =TYPE_VIRTIO_CCW_BUS , + .parent =TYPE_VIRTIO_BUS , + .instance_size =sizeof (VirtioCcwBusState), + .class_init = virtio_ccw_bus_class_init, +}; + +static void virtio_ccw_register (void ) +{
hw/s390x/virtio-ccw.c line 946
Quoted 10 lines
hw/s390x/virtio-ccw.c new file +10
-0+type_register_static (&virtio_ccw_bus_info); +type_register_static (&virtual_css_bus_info); +type_register_static (&virtio_ccw_device_info); +type_register_static (&virtio_ccw_serial); +type_register_static (&virtio_ccw_blk); +type_register_static (&virtio_ccw_net); +type_register_static (&virtio_ccw_balloon); +type_register_static (&virtio_ccw_scsi); +type_register_static (&virtual_css_bridge_info); +}
White line please if you resend.
Quoted 7 lines
hw/s390x/virtio-ccw.c new file +1
-0+type_init (virtio_ccw_register)hw/s390x/virtio-ccw.h new file +0
-0
hw/s390x/virtio-ccw.h line 10
Quoted 10 lines
hw/s390x/virtio-ccw.h new file +10
-0@@ -0,0 +1,94 @@ +/* +* virtio ccw target definitions +* +* Copyright 2012 IBM Corp. +* Author(s): Cornelia Huck <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/
Add a header guard?
#ifndef HW_S390X_VIRTIO_CCW_H
#define HW_S390X_VIRTIO_CCW_H
Quoted 16 lines
hw/s390x/virtio-ccw.h new file +16
-0+ +#include <hw/virtio-blk.h> +#include <hw/virtio-net.h> +#include <hw/virtio-serial.h> +#include <hw/virtio-scsi.h> +#include <hw/virtio-bus.h> + +#define VIRTUAL_CSSID 0xfe + +#define VIRTIO_CCW_CU_TYPE 0x3832 +#define VIRTIO_CCW_CHPID_TYPE 0x32 + +#define CCW_CMD_SET_VQ 0x13 +#define CCW_CMD_VDEV_RESET 0x33 +#define CCW_CMD_READ_FEAT 0x12 +#define CCW_CMD_WRITE_FEAT 0x11
hw/s390x/virtio-ccw.h line 36
Quoted 10 lines
hw/s390x/virtio-ccw.h new file +10
-0+#define CCW_CMD_READ_CONF 0x22 +#define CCW_CMD_WRITE_CONF 0x21 +#define CCW_CMD_WRITE_STATUS 0x31 +#define CCW_CMD_SET_IND 0x43 +#define CCW_CMD_SET_CONF_IND 0x53 +#define CCW_CMD_READ_VQ_CONF 0x32 + +#define TYPE_VIRTIO_CCW_DEVICE "virtio-ccw-device" +#define VIRTIO_CCW_DEVICE (obj) \ + OBJECT_CHECK(VirtioCcwData, (obj), TYPE_VIRTIO_CCW_DEVICE)
Why ...Data and not ...Device?
Quoted 64 lines
hw/s390x/virtio-ccw.h new file +58
-0+#define VIRTIO_CCW_DEVICE_CLASS (klass) \ + OBJECT_CLASS_CHECK(VirtIOCCWDeviceClass, (klass), TYPE_VIRTIO_CCW_DEVICE) +#define VIRTIO_CCW_DEVICE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(VirtIOCCWDeviceClass, (obj), TYPE_VIRTIO_CCW_DEVICE) + +typedef struct VirtioBusState VirtioCcwBusState ; +typedef struct VirtioBusClass VirtioCcwBusClass ; + +#define TYPE_VIRTIO_CCW_BUS "virtio-ccw-bus" +#define VIRTIO_CCW_BUS (obj) \ + OBJECT_CHECK(VirtioCcwBus, (obj), TYPE_VIRTIO_CCW_BUS) +#define VIRTIO_CCW_BUS_GET_CLASS (obj) \ + OBJECT_CHECK(VirtioCcwBusState, (obj), TYPE_VIRTIO_CCW_BUS) +#define VIRTIO_CCW_BUS_CLASS (klass) \ + OBJECT_CLASS_CHECK(VirtioCcwBusClass, klass, TYPE_VIRTIO_CCW_BUS) + +typedef struct VirtioCcwData VirtioCcwData ; + +void virtio_ccw_bus_new (VirtioBusState *bus,VirtioCcwData *dev); + +typedef struct VirtIOCCWDeviceClass { +DeviceClass parent_class; +int (*init)(VirtioCcwData *dev); +int (*exit)(VirtioCcwData *dev); +}VirtIOCCWDeviceClass ; + +/* Change here if we want to support more feature bits. */ +#define VIRTIO_CCW_FEATURE_SIZE 1 + +struct VirtioCcwData { +DeviceState parent_obj; +SubchDev *sch; +VirtIODevice *vdev; +char *bus_id; +VirtIOBlkConf blk; +NICConf nic; +uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE ]; +virtio_serial_conf serial; +virtio_net_conf net; +VirtIOSCSIConf scsi; +VirtioBusState bus; +/* Guest provided values: */ +hwaddr indicators; +hwaddr indicators2; +}; + +/* virtual css bus type */ +typedef struct VirtualCssBus { +BusState parent_obj; +}VirtualCssBus ; + +#define TYPE_VIRTUAL_CSS_BUS "virtual-css-bus" +#define VIRTUAL_CSS_BUS (obj) \ + OBJECT_CHECK(VirtualCssBus, (obj), TYPE_VIRTUAL_CSS_BUS) + +VirtualCssBus *virtual_css_bus_init (void ); +void virtio_ccw_device_update_status (SubchDev *sch); +VirtIODevice *virtio_ccw_get_vdev (SubchDev *sch);trace-events +0
-0
trace-events css_chpid_add(uint8_t cssid, uint8_t chpid, uint8_t type) "CSS: add chpid %x.%02 · line 1080
Quoted 7 lines
trace-events +4
-0@@ -1074,3 +1074,7 @@ css_chpid_add(uint8_t cssid, uint8_t chpid, uint8_t type) "CSS: add chpid %x.%02 css_new_image(uint8_t cssid, const char *default_cssid) "CSS: add css image %02x %s" css_assign_subch(const char *do_assign, uint8_t cssid, uint8_t ssid, uint16_t schid, uint16_t devno) "CSS: %s %x.%x.%04x (devno %04x)" css_io_interrupt(int cssid, int ssid, int schid, uint32_t intparm, uint8_t isc, const char *conditional) "CSS: I/O interrupt on sch %x.%x.%04x (intparm %08x, isc %x) %s" + +# hw/s390x/virtio-ccw.c +virtio_ccw_interpret_ccw(int cssid, int ssid, int schid, int cmd_code) "VIRTIO-CCW: %x.%x.%04x: interpret command %x" +virtio_ccw_new_device(int cssid, int ssid, int schid, int devno, const char *devno_mode) "VIRTIO-CCW: add subchannel %x.%x.%04x, devno %04x (%s)"
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Alexander Graf
AppliedQuoted 7 lines · Cornelia Huck
Hi,
another round for virtual channel I/O in qemu.
The patches have been respun against current master; changelogs are in the patches themselves.
Quoted 6 lines
Changes are mostly some cleanups; of note are the preparations for VirtioBus and some changes for making the code endianness aware.
Making s390-ccw-virtio the default machine has been deferred until after tcg support is available.
Thanks, applied [01..07], 09 to s390-next.
Alex
Re: [Qemu-devel] [PATCH 08/11] s390: Add new channel I/O based virtio transport.
In reply to Andreas FärberQuoted 43 lines · On Thu, 24 Jan 2013 14:18:10 +0100 Andreas Färber <[email protected]> wrote:
Am 24.01.2013 13:28, schrieb Cornelia Huck:
Quoted 42 lines
Add a new virtio transport that uses channel commands to perform virtio operations.
Signed-off-by Cornelia Huck <[email protected]>---
v5 -> v6:
- Get rid ofqemu_get_ram_ptrusage
- Adapt to virtual css changes
- Constify TypeInfos
- Prepare for VirtioBus--- hw/s390x/Makefile.objs | 1 + hw/s390x/virtio-ccw.c | 947 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 94 +++++ trace-events | 4 + 4 files changed, 1046 insertions(+) create mode 100644 hw/s390x/virtio-ccw.c create mode 100644 hw/s390x/virtio-ccw.hhw/s390x/Makefile.objs +1
-0@@ -7,3 +7,4 @@ obj-y += event-facility.o obj-y += sclpquiesce.o sclpconsole.o obj-y += ipl.o obj-y += css.o +obj-y += virtio-ccw.ohw/s390x/virtio-ccw.c new file +6
-0@@ -0,0 +1,947 @@ +/* +* virtio ccw target implementation +* +* Copyright 2012 IBM Corp. +* Author(s): Cornelia Huck <[email protected]> +*
Quoted 8 lines
hw/s390x/virtio-ccw.c line 12
Quoted 6 lines
hw/s390x/virtio-ccw.c new file +6
-0+* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ + +#include <hw/hw.h> "
hw/hw.h"?
ok
Quoted 64 lines
Quoted 64 lines
hw/s390x/virtio-ccw.c new file +63
-0+#include "block/block.h" +#include "sysemu/blockdev.h" +#include "sysemu/sysemu.h" +#include "net/net.h" +#include "monitor/monitor.h" +#include "hw/virtio.h" +#include "hw/virtio-serial.h" +#include "hw/virtio-net.h" +#include "hw/sysbus.h" +#include "qemu/bitops.h" +#include "hw/virtio-bus.h" + +#include "ioinst.h" +#include "css.h" +#include "virtio-ccw.h" +#include "trace.h" + +static const TypeInfo virtual_css_bus_info = { + .name =TYPE_VIRTUAL_CSS_BUS , + .parent =TYPE_BUS , + .instance_size =sizeof (VirtualCssBus), +}; + +static const VirtIOBindings virtio_ccw_bindings; + +VirtIODevice *virtio_ccw_get_vdev (SubchDev *sch) +{ +VirtIODevice *vdev =NULL ; + +if (sch->driver_data) { + vdev = ((VirtioCcwData *)sch->driver_data)->vdev; + } +return vdev; +} + +static void virtio_ccw_reset_subchannels (void *opaque) +{ +VirtualCssBus *bus = opaque; +BusChild *kid; +VirtioCcwData *data; +BusState *parent =BUS (bus); + + QTAILQ_FOREACH(kid, &parent->children, sibling) { + data = (VirtioCcwData *)kid->child; +virtio_reset (data->vdev); +css_reset_sch (data->sch); + } +css_reset (); +} + +VirtualCssBus *virtual_css_bus_init (void ) +{ +VirtualCssBus *cbus; +BusState *bus; +DeviceState *dev; + +/* Create bridge device */ + dev =qdev_create (NULL ,"virtual-css-bridge" ); +qdev_init_nofail (dev); + +/* Create bus on bridge device */ + bus =qbus_create (TYPE_VIRTUAL_CSS_BUS , dev,"virtual-css" ); + cbus =VIRTUAL_CSS_BUS (bus);
Quoted 8 lines
hw/s390x/virtio-ccw.c line 80
Quoted 5 lines
hw/s390x/virtio-ccw.c new file +5
-0+ +/* Enable hotplugging */ + bus->allow_hotplug =1 ; + +qemu_register_reset (virtio_ccw_reset_subchannels, cbus);Can't this be done via
BusClass::reset? (requires reordering before TypeInfo /class_init)
This got lost somewhere during my rebasing, I'll re-add.
Quoted 864 lines
Quoted 559 lines
hw/s390x/virtio-ccw.c new file +558
-0+return cbus; +} + +/* Communication blocks used by several channel commands. */ +typedef struct VqInfoBlock { +uint64_t queue; +uint32_t align; +uint16_t index; +uint16_t num; +} QEMU_PACKED VqInfoBlock; + +typedef struct VqConfigBlock { +uint16_t index; +uint16_t num_max; +} QEMU_PACKED VqConfigBlock; + +typedef struct VirtioFeatDesc { +uint32_t features; +uint8_t index; +} QEMU_PACKED VirtioFeatDesc; + +/* Specify where the virtqueues for the subchannel are in guest memory. */ +static int virtio_ccw_set_vqs (SubchDev *sch,uint64_t addr,uint32_t align, +uint16_t index,uint16_t num) +{ +VirtioCcwData *data = sch->driver_data; + +if (index >VIRTIO_PCI_QUEUE_MAX ) { +return -EINVAL ; + } + +/* Current code in virtio.c relies on 4K alignment. */ +if (addr && (align !=4096 )) { +return -EINVAL ; + } + +if (!data) { +return -EINVAL ; + } + +virtio_queue_set_addr (data->vdev, index, addr); +if (!addr) { +virtio_queue_set_vector (data->vdev, index,0 ); + }else { +/* Fail if we don't have a big enough queue. */ +/* TODO: Add interface to handle vring.num changing */ +if (virtio_queue_get_num (data->vdev, index) > num) { +return -EINVAL ; + } +virtio_queue_set_vector (data->vdev, index, index); + } +/* tell notify handler in case of config change */ + data->vdev->config_vector =VIRTIO_PCI_QUEUE_MAX ; +return 0 ; +} + +static int virtio_ccw_cb (SubchDev *sch,CCW1 ccw) +{ +int ret; +VqInfoBlock info; +uint8_t status; +VirtioFeatDesc features; +void *config; +hwaddr indicators; +VqConfigBlock vq_config; +VirtioCcwData *data = sch->driver_data; +bool check_len; +int len; +hwaddr hw_len; + +if (!data) { +return -EINVAL ; + } + +trace_virtio_ccw_interpret_ccw (sch->cssid, sch->ssid, sch->schid, + ccw.cmd_code); + check_len = !((ccw.flags &CCW_FLAG_SLI ) && !(ccw.flags &CCW_FLAG_DC )); + +/* Look at the command. */ +switch (ccw.cmd_code) { +case CCW_CMD_SET_VQ : +if (check_len) { +if (ccw.count !=sizeof (info)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (info)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; + }else { + info.queue =ldq_phys (ccw.cda); + info.align =ldl_phys (ccw.cda +sizeof (info.queue)); + info.index =lduw_phys (ccw.cda +sizeof (info.queue) + +sizeof (info.align)); + info.num =lduw_phys (ccw.cda +sizeof (info.queue) + +sizeof (info.align) + +sizeof (info.index)); + ret =virtio_ccw_set_vqs (sch, info.queue, info.align, info.index, + info.num); + sch->curr_status.scsw.count =0 ; + } +break ; +case CCW_CMD_VDEV_RESET : +virtio_reset (data->vdev); + ret =0 ; +break ; +case CCW_CMD_READ_FEAT : +if (check_len) { +if (ccw.count !=sizeof (features)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (features)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; + }else { + features.index =ldub_phys (ccw.cda +sizeof (features.features)); +if (features.index <ARRAY_SIZE (data->host_features)) { + features.features = data->host_features[features.index]; + }else { +/* Return zeroes if the guest supports more feature bits. */ + features.features =0 ; + } +stl_le_phys (ccw.cda, features.features); + sch->curr_status.scsw.count = ccw.count -sizeof (features); + ret =0 ; + } +break ; +case CCW_CMD_WRITE_FEAT : +if (check_len) { +if (ccw.count !=sizeof (features)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (features)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; + }else { + features.index =ldub_phys (ccw.cda +sizeof (features.features)); + features.features =ldl_le_phys (ccw.cda); +if (features.index <ARRAY_SIZE (data->host_features)) { +if (data->vdev->set_features) { + data->vdev->set_features (data->vdev, features.features); + } + data->vdev->guest_features = features.features; + }else { +/* +* If the guest supports more feature bits, assert that it +* passes us zeroes for those we don't support. +*/ +if (features.features) { +fprintf (stderr,"Guest bug: features[%i]=%x (expected 0)\n" , + features.index, features.features); +/* XXX: do a unit check here? */ + } + } + sch->curr_status.scsw.count = ccw.count -sizeof (features); + ret =0 ; + } +break ; +case CCW_CMD_READ_CONF : +if (check_len) { +if (ccw.count > data->vdev->config_len) { + ret = -EINVAL ; +break ; + } + } + len =MIN (ccw.count, data->vdev->config_len); +if (!ccw.cda) { + ret = -EFAULT ; + }else { + data->vdev->get_config (data->vdev, data->vdev->config); +/* XXX config space endianness */ +cpu_physical_memory_write (ccw.cda, data->vdev->config, len); + sch->curr_status.scsw.count = ccw.count - len; + ret =0 ; + } +break ; +case CCW_CMD_WRITE_CONF : +if (check_len) { +if (ccw.count > data->vdev->config_len) { + ret = -EINVAL ; +break ; + } + } + len =MIN (ccw.count, data->vdev->config_len); + hw_len = len; +if (!ccw.cda) { + ret = -EFAULT ; + }else { + config =cpu_physical_memory_map (ccw.cda, &hw_len,0 ); +if (!config) { + ret = -EFAULT ; + }else { + len = hw_len; +/* XXX config space endianness */ +memcpy (data->vdev->config, config, len); +cpu_physical_memory_unmap (config, hw_len,0 , hw_len); +if (data->vdev->set_config) { + data->vdev->set_config (data->vdev, data->vdev->config); + } + sch->curr_status.scsw.count = ccw.count - len; + ret =0 ; + } + } +break ; +case CCW_CMD_WRITE_STATUS : +if (check_len) { +if (ccw.count !=sizeof (status)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (status)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; + }else { + status =ldub_phys (ccw.cda); +virtio_set_status (data->vdev, status); + sch->curr_status.scsw.count = ccw.count -sizeof (status); + ret =0 ; + } +break ; +case CCW_CMD_SET_IND : +if (check_len) { +if (ccw.count !=sizeof (indicators)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (indicators)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } + indicators =ldq_phys (ccw.cda); +if (!indicators) { + ret = -EFAULT ; + }else { + data->indicators = indicators; + sch->curr_status.scsw.count = ccw.count -sizeof (indicators); + ret =0 ; + } +break ; +case CCW_CMD_SET_CONF_IND : +if (check_len) { +if (ccw.count !=sizeof (indicators)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (indicators)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } + indicators =ldq_phys (ccw.cda); +if (!indicators) { + ret = -EFAULT ; + }else { + data->indicators2 = indicators; + sch->curr_status.scsw.count = ccw.count -sizeof (indicators); + ret =0 ; + } +break ; +case CCW_CMD_READ_VQ_CONF : +if (check_len) { +if (ccw.count !=sizeof (vq_config)) { + ret = -EINVAL ; +break ; + } + }else if (ccw.count <sizeof (vq_config)) { +/* Can't execute command. */ + ret = -EINVAL ; +break ; + } +if (!ccw.cda) { + ret = -EFAULT ; + }else { + vq_config.index =lduw_phys (ccw.cda); + vq_config.num_max =virtio_queue_get_num (data->vdev, + vq_config.index); +stw_phys (ccw.cda +sizeof (vq_config.index), vq_config.num_max); + sch->curr_status.scsw.count = ccw.count -sizeof (vq_config); + ret =0 ; + } +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +return ret; +} + +static int virtio_ccw_device_init (VirtioCcwData *dev,VirtIODevice *vdev) +{ +unsigned int cssid =0 ; +unsigned int ssid =0 ; +unsigned int schid; +unsigned int devno; +bool have_devno = false; +bool found = false; +SubchDev *sch; +int ret; +int num; +DeviceState *parent =DEVICE (dev); + + sch =g_malloc0 (sizeof (SubchDev)); + + sch->driver_data = dev; + dev->sch = sch; + + dev->vdev = vdev; + dev->indicators =0 ; + +/* Initialize subchannel structure. */ + sch->channel_prog =0x0 ; + sch->last_cmd_valid = false; + sch->orb =NULL ; +/* +* Use a device number if provided. Otherwise, fall back to subchannel +* number. +*/ +if (dev->bus_id) { + num =sscanf (dev->bus_id,"%x.%x.%04x" , &cssid, &ssid, &devno); +if (num ==3 ) { +if ((cssid >MAX_CSSID ) || (ssid >MAX_SSID )) { + ret = -EINVAL ; +error_report ("Invalid cssid or ssid: cssid %x, ssid %x" , + cssid, ssid); + goto out_err; + } +/* Enforce use of virtual cssid. */ +if (cssid !=VIRTUAL_CSSID ) { + ret = -EINVAL ; +error_report ("cssid %x not valid for virtio devices" , cssid); + goto out_err; + } +if (css_devno_used (cssid, ssid, devno)) { + ret = -EEXIST ; +error_report ("Device %x.%x.%04x already exists" , cssid, ssid, + devno); + goto out_err; + } + sch->cssid = cssid; + sch->ssid = ssid; + sch->devno = devno; + have_devno = true; + }else { + ret = -EINVAL ; +error_report ("Malformed devno parameter '%s'" , dev->bus_id); + goto out_err; + } + } + +/* Find the next free id. */ +if (have_devno) { +for (schid =0 ; schid <=MAX_SCHID ; schid++) { +if (!css_find_subch (1 , cssid, ssid, schid)) { + sch->schid = schid; +css_subch_assign (cssid, ssid, schid, devno, sch); + found = true; +break ; + } + } +if (!found) { + ret = -ENODEV ; +error_report ("No free subchannel found for %x.%x.%04x" , cssid, ssid, + devno); + goto out_err; + } +trace_virtio_ccw_new_device (cssid, ssid, schid, devno, +"user-configured" ); + }else { + cssid =VIRTUAL_CSSID ; +for (ssid =0 ; ssid <=MAX_SSID ; ssid++) { +for (schid =0 ; schid <=MAX_SCHID ; schid++) { +if (!css_find_subch (1 , cssid, ssid, schid)) { + sch->cssid = cssid; + sch->ssid = ssid; + sch->schid = schid; + devno = schid; +/* +* If the devno is already taken, look further in this +* subchannel set. +*/ +while (css_devno_used (cssid, ssid, devno)) { +if (devno ==MAX_SCHID ) { + devno =0 ; + }else if (devno == schid -1 ) { + ret = -ENODEV ; +error_report ("No free devno found" ); + goto out_err; + }else { + devno++; + } + } + sch->devno = devno; +css_subch_assign (cssid, ssid, schid, devno, sch); + found = true; +break ; + } + } +if (found) { +break ; + } + } +if (!found) { + ret = -ENODEV ; +error_report ("Virtual channel subsystem is full!" ); + goto out_err; + } +trace_virtio_ccw_new_device (cssid, ssid, schid, devno, +"auto-configured" ); + } + +/* Build initial schib. */ +css_sch_build_virtual_schib (sch,0 ,VIRTIO_CCW_CHPID_TYPE ); + + sch->ccw_cb = virtio_ccw_cb; + +/* Build senseid data. */ +memset (&sch->id,0 ,sizeof (SenseId)); + sch->id.reserved =0xff ; + sch->id.cu_type =VIRTIO_CCW_CU_TYPE ; + sch->id.cu_model = dev->vdev->device_id; + +virtio_bind_device (vdev, &virtio_ccw_bindings,DEVICE (dev)); +/* Only the first 32 feature bits are used. */ + dev->host_features[0 ] = vdev->get_features (vdev, dev->host_features[0 ]); + dev->host_features[0 ] |=0x1 <<VIRTIO_F_NOTIFY_ON_EMPTY ; + dev->host_features[0 ] |=0x1 <<VIRTIO_F_BAD_FEATURE ; + +css_generate_sch_crws (sch->cssid, sch->ssid, sch->schid, + parent->hotplugged,1 ); +return 0 ; + +out_err: + dev->sch =NULL ; +g_free (sch); +return ret; +} + +static int virtio_ccw_exit (VirtioCcwData *dev) +{ +SubchDev *sch = dev->sch; + +if (sch) { +css_subch_assign (sch->cssid, sch->ssid, sch->schid, sch->devno,NULL ); +g_free (sch); + } + dev->indicators =0 ; +return 0 ; +} + +static int virtio_ccw_net_init (VirtioCcwData *dev) +{ +VirtIODevice *vdev; + + vdev =virtio_net_init ((DeviceState *)dev, &dev->nic, &dev->net); +if (!vdev) { +return -1 ; + } + +return virtio_ccw_device_init (dev, vdev); +} + +static int virtio_ccw_net_exit (VirtioCcwData *dev) +{ +virtio_net_exit (dev->vdev); +return virtio_ccw_exit (dev); +} + +static int virtio_ccw_blk_init (VirtioCcwData *dev) +{ +VirtIODevice *vdev; + + vdev =virtio_blk_init ((DeviceState *)dev, &dev->blk); +if (!vdev) { +return -1 ; + } + +return virtio_ccw_device_init (dev, vdev); +} + +static int virtio_ccw_blk_exit (VirtioCcwData *dev) +{ +virtio_blk_exit (dev->vdev); +blockdev_mark_auto_del (dev->blk.conf.bs); +return virtio_ccw_exit (dev); +} + +static int virtio_ccw_serial_init (VirtioCcwData *dev) +{ +VirtIODevice *vdev; + + vdev =virtio_serial_init ((DeviceState *)dev, &dev->serial); +if (!vdev) { +return -1 ; + } + +return virtio_ccw_device_init (dev, vdev); +} + +static int virtio_ccw_serial_exit (VirtioCcwData *dev) +{ +virtio_serial_exit (dev->vdev); +return virtio_ccw_exit (dev); +} + +static int virtio_ccw_balloon_init (VirtioCcwData *dev) +{ +VirtIODevice *vdev; + + vdev =virtio_balloon_init ((DeviceState *)dev); +if (!vdev) { +return -1 ; + } + +return virtio_ccw_device_init (dev, vdev); +} + +static int virtio_ccw_balloon_exit (VirtioCcwData *dev) +{ +virtio_balloon_exit (dev->vdev); +return virtio_ccw_exit (dev); +} + +static int virtio_ccw_scsi_init (VirtioCcwData *dev) +{ +VirtIODevice *vdev; + + vdev =virtio_scsi_init ((DeviceState *)dev, &dev->scsi); +if (!vdev) { +return -1 ; + } + +return virtio_ccw_device_init (dev, vdev); +} + +static int virtio_ccw_scsi_exit (VirtioCcwData *dev) +{ +virtio_scsi_exit (dev->vdev); +return virtio_ccw_exit (dev); +}hw/s390x/virtio-ccw.c line 648
Quoted 10 lines
hw/s390x/virtio-ccw.c new file +10
-0+ +/* DeviceState to VirtioCcwData. Note: used on datapath, +* be careful and test performance if you change this. +*/ +static inline VirtioCcwData *to_virtio_ccw_data_fast (DeviceState *d) +{ +return container_of (d, VirtioCcwData, parent_obj); +} + +/* DeviceState to VirtioCcwData. TODO: use QOM. */ Are the prerequisites to resolve this TODO not yet in qemu.git?
Quoted 292 lines
hw/s390x/virtio-ccw.c new file +292
-0+static inline VirtioCcwData *to_virtio_ccw_data (DeviceState *d) +{ +return container_of (d, VirtioCcwData, parent_obj); +} + +static void virtio_ccw_notify (DeviceState *d,uint16_t vector) +{ +VirtioCcwData *dev =to_virtio_ccw_data_fast (d); +SubchDev *sch = dev->sch; +uint64_t indicators; + +if (vector >=128 ) { +return ; + } + +if (vector <VIRTIO_PCI_QUEUE_MAX ) { + indicators =ldq_phys (dev->indicators); +set_bit (vector, &indicators); +stq_phys (dev->indicators, indicators); + }else { + vector =0 ; + indicators =ldq_phys (dev->indicators2); +set_bit (vector, &indicators); +stq_phys (dev->indicators2, indicators); + } + +css_conditional_io_interrupt (sch); + +} + +static unsigned virtio_ccw_get_features (DeviceState *d) +{ +VirtioCcwData *dev =to_virtio_ccw_data (d); + +/* Only the first 32 feature bits are used. */ +return dev->host_features[0 ]; +} + +/**************** Virtio-ccw Bus Device Descriptions *******************/ + +static const VirtIOBindings virtio_ccw_bindings = { + .notify = virtio_ccw_notify, + .get_features = virtio_ccw_get_features, +}; + +static Property virtio_ccw_net_properties[] = { +DEFINE_PROP_STRING ("devno" , VirtioCcwData, bus_id), +DEFINE_VIRTIO_NET_FEATURES (VirtioCcwData, host_features[0 ]), +DEFINE_NIC_PROPERTIES (VirtioCcwData, nic), +DEFINE_PROP_UINT32 ("x-txtimer" , VirtioCcwData, + net.txtimer,TX_TIMER_INTERVAL ), +DEFINE_PROP_INT32 ("x-txburst" , VirtioCcwData, + net.txburst,TX_BURST ), +DEFINE_PROP_STRING ("tx" , VirtioCcwData, net.tx), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_ccw_net_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtIOCCWDeviceClass *k =VIRTIO_CCW_DEVICE_CLASS (klass); + + k->init = virtio_ccw_net_init; + k->exit = virtio_ccw_net_exit; + dc->props = virtio_ccw_net_properties; +} + +static const TypeInfo virtio_ccw_net = { + .name ="virtio-net-ccw" , + .parent =TYPE_VIRTIO_CCW_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_net_class_init, +}; + +static Property virtio_ccw_blk_properties[] = { +DEFINE_PROP_STRING ("devno" , VirtioCcwData, bus_id), +DEFINE_BLOCK_PROPERTIES (VirtioCcwData, blk.conf), +DEFINE_PROP_STRING ("serial" , VirtioCcwData, blk.serial), +#ifdef __linux__ +DEFINE_PROP_BIT ("scsi" , VirtioCcwData, blk.scsi,0 , true), +#endif +DEFINE_VIRTIO_BLK_FEATURES (VirtioCcwData, host_features[0 ]), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_ccw_blk_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtIOCCWDeviceClass *k =VIRTIO_CCW_DEVICE_CLASS (klass); + + k->init = virtio_ccw_blk_init; + k->exit = virtio_ccw_blk_exit; + dc->props = virtio_ccw_blk_properties; +} + +static const TypeInfo virtio_ccw_blk = { + .name ="virtio-blk-ccw" , + .parent =TYPE_VIRTIO_CCW_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_blk_class_init, +}; + +static Property virtio_ccw_serial_properties[] = { +DEFINE_PROP_STRING ("devno" , VirtioCcwData, bus_id), +DEFINE_PROP_UINT32 ("max_ports" , VirtioCcwData, serial.max_virtserial_ports, +31 ), +DEFINE_VIRTIO_COMMON_FEATURES (VirtioCcwData, host_features[0 ]), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_ccw_serial_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtIOCCWDeviceClass *k =VIRTIO_CCW_DEVICE_CLASS (klass); + + k->init = virtio_ccw_serial_init; + k->exit = virtio_ccw_serial_exit; + dc->props = virtio_ccw_serial_properties; +} + +static const TypeInfo virtio_ccw_serial = { + .name ="virtio-serial-ccw" , + .parent =TYPE_VIRTIO_CCW_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_serial_class_init, +}; + +static Property virtio_ccw_balloon_properties[] = { +DEFINE_PROP_STRING ("devno" , VirtioCcwData, bus_id), +DEFINE_VIRTIO_COMMON_FEATURES (VirtioCcwData, host_features[0 ]), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_ccw_balloon_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtIOCCWDeviceClass *k =VIRTIO_CCW_DEVICE_CLASS (klass); + + k->init = virtio_ccw_balloon_init; + k->exit = virtio_ccw_balloon_exit; + dc->props = virtio_ccw_balloon_properties; +} + +static const TypeInfo virtio_ccw_balloon = { + .name ="virtio-balloon-ccw" , + .parent =TYPE_VIRTIO_CCW_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_balloon_class_init, +}; + +static Property virtio_ccw_scsi_properties[] = { +DEFINE_PROP_STRING ("devno" , VirtioCcwData, bus_id), +DEFINE_VIRTIO_SCSI_PROPERTIES (VirtioCcwData, host_features[0 ], scsi), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_ccw_scsi_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtIOCCWDeviceClass *k =VIRTIO_CCW_DEVICE_CLASS (klass); + + k->init = virtio_ccw_scsi_init; + k->exit = virtio_ccw_scsi_exit; + dc->props = virtio_ccw_scsi_properties; +} + +static const TypeInfo virtio_ccw_scsi = { + .name ="virtio-scsi-ccw" , + .parent =TYPE_VIRTIO_CCW_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_scsi_class_init, +}; + +static int virtio_ccw_busdev_init (DeviceState *dev) +{ +VirtioCcwData *_dev = (VirtioCcwData *)dev; +VirtIOCCWDeviceClass *_info =VIRTIO_CCW_DEVICE_GET_CLASS (dev); + +virtio_ccw_bus_new (&_dev->bus, _dev); + +return _info->init (_dev); +} + +static int virtio_ccw_busdev_exit (DeviceState *dev) +{ +VirtioCcwData *_dev = (VirtioCcwData *)dev; +VirtIOCCWDeviceClass *_info =VIRTIO_CCW_DEVICE_GET_CLASS (dev); + +return _info->exit (_dev); +} + +static int virtio_ccw_busdev_unplug (DeviceState *dev) +{ +VirtioCcwData *_dev = (VirtioCcwData *)dev; +SubchDev *sch = _dev->sch; + +/* +* We should arrive here only for device_del, since we don't support +* direct hot(un)plug of channels, but only through virtio. +*/ +assert (sch !=NULL ); +/* Subchannel is now disabled and no longer valid. */ + sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA | +PMCW_FLAGS_MASK_DNV ); + +css_generate_sch_crws (sch->cssid, sch->ssid, sch->schid,1 ,0 ); + +object_unparent (OBJECT (dev)); +qdev_free (dev); +return 0 ; +} + +static void virtio_ccw_device_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->init = virtio_ccw_busdev_init; + dc->exit = virtio_ccw_busdev_exit; + dc->unplug = virtio_ccw_busdev_unplug; + dc->bus_type =TYPE_VIRTUAL_CSS_BUS ; + +} + +static const TypeInfo virtio_ccw_device_info = { + .name =TYPE_VIRTIO_CCW_DEVICE , + .parent =TYPE_DEVICE , + .instance_size =sizeof (VirtioCcwData), + .class_init = virtio_ccw_device_class_init, + .class_size =sizeof (VirtIOCCWDeviceClass), + .abstract = true, +}; + +/***************** Virtual-css Bus Bridge Device ********************/ +/* Only required to have the virtio bus as child in the system bus */ + +static int virtual_css_bridge_init (SysBusDevice *dev) +{ +/* nothing */ +return 0 ; +} + +static void virtual_css_bridge_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); + + k->init = virtual_css_bridge_init; + dc->no_user =1 ; +} + +static const TypeInfo virtual_css_bridge_info = { + .name ="virtual-css-bridge" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (SysBusDevice), + .class_init = virtual_css_bridge_class_init, +}; + +/* virtio-ccw-bus */ + +void virtio_ccw_bus_new (VirtioBusState *bus,VirtioCcwData *dev) +{ +DeviceState *qdev =DEVICE (dev); +BusState *qbus; + +qbus_create_inplace ((BusState *)bus,TYPE_VIRTIO_CCW_BUS , qdev,NULL ); + qbus =BUS (bus); + qbus->allow_hotplug =0 ; +} + +static void virtio_ccw_bus_class_init (ObjectClass *klass,void *data) +{ +VirtioBusClass *k =VIRTIO_BUS_CLASS (klass); +BusClass *bus_class =BUS_CLASS (klass); + + bus_class->max_dev =1 ; + k->notify = virtio_ccw_notify; + k->get_features = virtio_ccw_get_features; +} + +static const TypeInfo virtio_ccw_bus_info = { + .name =TYPE_VIRTIO_CCW_BUS , + .parent =TYPE_VIRTIO_BUS , + .instance_size =sizeof (VirtioCcwBusState), + .class_init = virtio_ccw_bus_class_init, +}; + +static void virtio_ccw_register (void ) +{ +type_register_static (&virtio_ccw_bus_info); +type_register_static (&virtual_css_bus_info); +type_register_static (&virtio_ccw_device_info); +type_register_static (&virtio_ccw_serial);
Quoted 8 lines
hw/s390x/virtio-ccw.c line 946
Quoted 6 lines
hw/s390x/virtio-ccw.c new file +6
-0+type_register_static (&virtio_ccw_blk); +type_register_static (&virtio_ccw_net); +type_register_static (&virtio_ccw_balloon); +type_register_static (&virtio_ccw_scsi); +type_register_static (&virtual_css_bridge_info); +}White line please if you resend.
ok
Quoted 21 lines
Quoted 8 lines
hw/s390x/virtio-ccw.c new file +1
-0+type_init (virtio_ccw_register)hw/s390x/virtio-ccw.h new file +0
-0hw/s390x/virtio-ccw.h line 10
Quoted 10 lines
hw/s390x/virtio-ccw.h new file +10
-0@@ -0,0 +1,94 @@ +/* +* virtio ccw target definitions +* +* Copyright 2012 IBM Corp. +* Author(s): Cornelia Huck <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ Add a header guard?
Quoted 2 lines
#ifndef
HW_S390X_VIRTIO_CCW_H
#defineHW_S390X_VIRTIO_CCW_H
yup
Quoted 21 lines
Quoted 21 lines
hw/s390x/virtio-ccw.h new file +20
-0+ +#include <hw/virtio-blk.h> +#include <hw/virtio-net.h> +#include <hw/virtio-serial.h> +#include <hw/virtio-scsi.h> +#include <hw/virtio-bus.h> + +#define VIRTUAL_CSSID 0xfe + +#define VIRTIO_CCW_CU_TYPE 0x3832 +#define VIRTIO_CCW_CHPID_TYPE 0x32 + +#define CCW_CMD_SET_VQ 0x13 +#define CCW_CMD_VDEV_RESET 0x33 +#define CCW_CMD_READ_FEAT 0x12 +#define CCW_CMD_WRITE_FEAT 0x11 +#define CCW_CMD_READ_CONF 0x22 +#define CCW_CMD_WRITE_CONF 0x21 +#define CCW_CMD_WRITE_STATUS 0x31 +#define CCW_CMD_SET_IND 0x43
Quoted 8 lines
hw/s390x/virtio-ccw.h line 36
Quoted 6 lines
hw/s390x/virtio-ccw.h new file +6
-0+#define CCW_CMD_SET_CONF_IND 0x53 +#define CCW_CMD_READ_VQ_CONF 0x32 + +#define TYPE_VIRTIO_CCW_DEVICE "virtio-ccw-device" +#define VIRTIO_CCW_DEVICE (obj) \ + OBJECT_CHECK(VirtioCcwData, (obj), TYPE_VIRTIO_CCW_DEVICE)Why ...Data and not ...Device?
Historical reasons, I've changed it now.
Quoted 66 lines
Quoted 66 lines
hw/s390x/virtio-ccw.h new file +58
-0+#define VIRTIO_CCW_DEVICE_CLASS (klass) \ + OBJECT_CLASS_CHECK(VirtIOCCWDeviceClass, (klass), TYPE_VIRTIO_CCW_DEVICE) +#define VIRTIO_CCW_DEVICE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(VirtIOCCWDeviceClass, (obj), TYPE_VIRTIO_CCW_DEVICE) + +typedef struct VirtioBusState VirtioCcwBusState ; +typedef struct VirtioBusClass VirtioCcwBusClass ; + +#define TYPE_VIRTIO_CCW_BUS "virtio-ccw-bus" +#define VIRTIO_CCW_BUS (obj) \ + OBJECT_CHECK(VirtioCcwBus, (obj), TYPE_VIRTIO_CCW_BUS) +#define VIRTIO_CCW_BUS_GET_CLASS (obj) \ + OBJECT_CHECK(VirtioCcwBusState, (obj), TYPE_VIRTIO_CCW_BUS) +#define VIRTIO_CCW_BUS_CLASS (klass) \ + OBJECT_CLASS_CHECK(VirtioCcwBusClass, klass, TYPE_VIRTIO_CCW_BUS) + +typedef struct VirtioCcwData VirtioCcwData ; + +void virtio_ccw_bus_new (VirtioBusState *bus,VirtioCcwData *dev); + +typedef struct VirtIOCCWDeviceClass { +DeviceClass parent_class; +int (*init)(VirtioCcwData *dev); +int (*exit)(VirtioCcwData *dev); +}VirtIOCCWDeviceClass ; + +/* Change here if we want to support more feature bits. */ +#define VIRTIO_CCW_FEATURE_SIZE 1 + +struct VirtioCcwData { +DeviceState parent_obj; +SubchDev *sch; +VirtIODevice *vdev; +char *bus_id; +VirtIOBlkConf blk; +NICConf nic; +uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE ]; +virtio_serial_conf serial; +virtio_net_conf net; +VirtIOSCSIConf scsi; +VirtioBusState bus; +/* Guest provided values: */ +hwaddr indicators; +hwaddr indicators2; +}; + +/* virtual css bus type */ +typedef struct VirtualCssBus { +BusState parent_obj; +}VirtualCssBus ; + +#define TYPE_VIRTUAL_CSS_BUS "virtual-css-bus" +#define VIRTUAL_CSS_BUS (obj) \ + OBJECT_CHECK(VirtualCssBus, (obj), TYPE_VIRTUAL_CSS_BUS) + +VirtualCssBus *virtual_css_bus_init (void ); +void virtio_ccw_device_update_status (SubchDev *sch); +VirtIODevice *virtio_ccw_get_vdev (SubchDev *sch);trace-events +0
-0@@ -1074,3 +1074,7 @@ css_chpid_add(uint8_t cssid, uint8_t chpid, uint8_t type) "CSS: add chpid %x.%02 css_new_image(uint8_t cssid, const char *default_cssid) "CSS: add css image %02x %s" css_assign_subch(const char *do_assign, uint8_t cssid, uint8_t ssid, uint16_t schid, uint16_t devno) "CSS: %s %x.%x.%04x (devno %04x)"
Quoted 9 lines
trace-events css_chpid_add(uint8_t cssid, uint8_t chpid, uint8_t type) "CSS: add chpid %x.%02 · line 1080
Quoted 6 lines
trace-events +4
-0css_io_interrupt(int cssid, int ssid, int schid, uint32_t intparm, uint8_t isc, const char *conditional) "CSS: I/O interrupt on sch %x.%x.%04x (intparm %08x, isc %x) %s" + +# hw/s390x/virtio-ccw.c +virtio_ccw_interpret_ccw(int cssid, int ssid, int schid, int cmd_code) "VIRTIO-CCW: %x.%x.%04x: interpret command %x" +virtio_ccw_new_device(int cssid, int ssid, int schid, int devno, const char *devno_mode) "VIRTIO-CCW: add subchannel %x.%x.%04x, devno %04x (%s)"Andreas
Will rebase against s390-next and resend.
Re: [Qemu-devel] [PATCH 08/11] s390: Add new channel I/O based virtio transport.
In reply to Andreas FärberOn Thu, 24 Jan 2013 14:18:10 +0100
Andreas Färber <[email protected]> wrote:
Forgot one point :)
Quoted 11 lines
hw/s390x/virtio-ccw.c line 648
Quoted 9 lines
hw/s390x/virtio-ccw.c new file +9
-0+/* DeviceState to VirtioCcwData. Note: used on datapath, +* be careful and test performance if you change this. +*/ +static inline VirtioCcwData *to_virtio_ccw_data_fast (DeviceState *d) +{ +return container_of (d, VirtioCcwData, parent_obj); +} + +/* DeviceState to VirtioCcwData. TODO: use QOM. */ Are the prerequisites to resolve this TODO not yet in qemu.git?
This is copied verbatim from s390-virtio-bus/virtio-pci; my guess it that it will be resolved tree-wide.
Quoted 6 lines
Quoted 6 lines
hw/s390x/virtio-ccw.c new file +5
-0+static inline VirtioCcwData *to_virtio_ccw_data (DeviceState *d) +{ +return container_of (d, VirtioCcwData, parent_obj); +} +
Re: [Qemu-devel] [PATCH 08/11] s390: Add new channel I/O based virtio transport.
Am 24.01.2013 15:42, schrieb Cornelia Huck:
Quoted 21 lines
On Thu, 24 Jan 2013 14:18:10 +0100
Andreas Färber <[email protected]> wrote:Forgot one point :)
Quoted 11 lines
hw/s390x/virtio-ccw.c line 648
Quoted 9 lines
hw/s390x/virtio-ccw.c new file +9
-0+/* DeviceState to VirtioCcwData. Note: used on datapath, +* be careful and test performance if you change this. +*/ +static inline VirtioCcwData *to_virtio_ccw_data_fast (DeviceState *d) +{ +return container_of (d, VirtioCcwData, parent_obj); +} + +/* DeviceState to VirtioCcwData. TODO: use QOM. */ Are the prerequisites to resolve this TODO not yet in qemu.git?
This is copied verbatim from s390-virtio-bus/virtio-pci; my guess it that it will be resolved tree-wide.
Quoted 1 line
Quoted 5 lines
Quoted 5 lines
hw/s390x/virtio-ccw.c line 653
Quoted 5 lines
hw/s390x/virtio-ccw.c new file +5
-0+static inline VirtioCcwData *to_virtio_ccw_data (DeviceState *d) +{ +return container_of (d, VirtioCcwData, parent_obj); +} +
You did introduce VIRTIO_CCW_DEVICE(obj) though, no? Then you can drop this function and use it instead. Can be a follow-up but it seems a file-local issue to me.
Cheers,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Hi,
Thank you for submitting your patch series. checkpatch.pl has detected that one or more of the patches in this series violate the QEMU coding style.
If you believe this message was sent in error, please ignore it or respond here with an explanation.
Otherwise, please correct the coding style issues and resubmit a new version of the patch.
For more information about QEMU coding style, see:
http://git.qemu.org/?p=qemu.git;a=blob_plain;f=CODING_STYLE;hb=HEAD
Here is the output from checkpatch.pl:
Subject: s390: Add s390-ccw-virtio machine.
Subject: s390: Add default support for SCLP console
ERROR: do not initialise statics to 0 or NULL #72: FILE: vl.c:2468:
+ static int index = 0;
WARNING: braces {} are necessary for all arms of this statement #126: FILE: vl.c:3923:
+ if (default_sclp)
[...]
WARNING: braces {} are necessary for all arms of this statement #135: FILE: vl.c:3937:
+ if (default_sclp)
[...]
WARNING: braces {} are necessary for all arms of this statement #144: FILE: vl.c:4109:
+ if (foreach_device_config(DEV_SCLP, sclp_parse) < 0)
[...]
total: 1 errors, 3 warnings, 114 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Subject: s390-virtio: Factor out some initialization code.
Subject: s390: Add new channel I/O based virtio transport.
Subject: s390: Wire up channel I/O in kvm.
Subject: s390: Virtual channel subsystem support.
ERROR: need consistent spacing around '*' (ctx:WxV) #56: FILE: hw/s390x/css.c:31:
+ SubchDev *sch[MAX_SCHID + 1];
^ERROR: need consistent spacing around '*' (ctx:WxV) #62: FILE: hw/s390x/css.c:37:
+ SubchSet *sch_set[MAX_SSID + 1];
^ERROR: need consistent spacing around '*' (ctx:WxV) #74: FILE: hw/s390x/css.c:49:
+ CssImage *css[MAX_CSSID + 1];
^total: 3 errors, 0 warnings, 1469 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Subject: s390: Add channel I/O instructions.
Subject: s390: I/O interrupt and machine check injection.
Subject: s390: Channel I/O basic definitions.
Subject: s390: Add mapping helper functions.
Subject: s390: Lowcore mapping helper.
Regards,
Anthony Liguori