From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=40996 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ojck8-00020e-Vq for qemu-devel@nongnu.org; Thu, 12 Aug 2010 14:43:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ojck7-00023X-7M for qemu-devel@nongnu.org; Thu, 12 Aug 2010 14:43:08 -0400 Received: from mail-qw0-f45.google.com ([209.85.216.45]:46257) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ojck6-00023S-Ve for qemu-devel@nongnu.org; Thu, 12 Aug 2010 14:43:07 -0400 Received: by qwh5 with SMTP id 5so1911084qwh.4 for ; Thu, 12 Aug 2010 11:43:06 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <1281622202-3453-9-git-send-email-stefano.stabellini@eu.citrix.com> References: <1281622202-3453-9-git-send-email-stefano.stabellini@eu.citrix.com> From: Blue Swirl Date: Thu, 12 Aug 2010 18:42:46 +0000 Message-ID: Subject: Re: [Qemu-devel] [PATCH 09/15] xen: Initialize event channels and io rings Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: stefano.stabellini@eu.citrix.com Cc: Anthony.Perard@citrix.com, xen-devel@lists.xensource.com, qemu-devel@nongnu.org On Thu, Aug 12, 2010 at 2:09 PM, wrote: > From: Anthony PERARD > > Open and bind event channels; map ioreq and buffered ioreq rings. > > Signed-off-by: Anthony PERARD > Signed-off-by: Stefano Stabellini > --- > =C2=A0hw/xen_machine_fv.c =C2=A0 | =C2=A0 25 ++++ > =C2=A0target-xen/cpu.h =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A01 + > =C2=A0target-xen/helper.c =C2=A0 | =C2=A0362 ++++++++++++++++++++++++++++= +++++++++++++++++++++ > =C2=A0target-xen/qemu-xen.h | =C2=A0 =C2=A02 + > =C2=A04 files changed, 390 insertions(+), 0 deletions(-) > > diff --git a/hw/xen_machine_fv.c b/hw/xen_machine_fv.c > index a6e778a..b1bc88d 100644 > --- a/hw/xen_machine_fv.c > +++ b/hw/xen_machine_fv.c > @@ -22,6 +22,9 @@ > =C2=A0* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEA= LINGS IN > =C2=A0* THE SOFTWARE. > =C2=A0*/ > +#include "config.h" > + > +#include > > =C2=A0#include "hw.h" > =C2=A0#include "pc.h" > @@ -71,12 +74,34 @@ static void xen_init_fv(ram_addr_t ram_size, > > =C2=A0 =C2=A0 CPUState *env; > > + =C2=A0 =C2=A0unsigned long ioreq_pfn; > + =C2=A0 =C2=A0extern void *shared_page; > + =C2=A0 =C2=A0extern void *buffered_io_page; These should be defined in a header file. > + > =C2=A0 =C2=A0 /* Initialize backend core & drivers */ > =C2=A0 =C2=A0 if (xen_dm_init() !=3D 0) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "%s: xen backend core setup f= ailed\n", __FUNCTION__); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 exit(1); > =C2=A0 =C2=A0 } > > + =C2=A0 =C2=A0xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_IOREQ_PFN, &= ioreq_pfn); > + =C2=A0 =C2=A0fprintf(stderr, "shared page at pfn %lx\n", ioreq_pfn); > + =C2=A0 =C2=A0shared_page =3D xc_map_foreign_range(xen_xc, xen_domid, XC= _PAGE_SIZE, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0PROT_READ|PROT_WRITE, ioreq_pf= n); > + =C2=A0 =C2=A0if (shared_page =3D=3D NULL) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "map shared IO page returned= error %d handle=3D%p\n", errno, xen_xc); hw_error()? > + =C2=A0 =C2=A0 =C2=A0 =C2=A0exit(-1); > + =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_BUFIOREQ_PFN= , &ioreq_pfn); > + =C2=A0 =C2=A0fprintf(stderr, "buffered io page at pfn %lx\n", ioreq_pfn= ); > + =C2=A0 =C2=A0buffered_io_page =3D xc_map_foreign_range(xen_xc, xen_domi= d, XC_PAGE_SIZE, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0PROT_READ|PROT_WRITE, ioreq_pfn); > + =C2=A0 =C2=A0if (buffered_io_page =3D=3D NULL) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(logfile, "map buffered IO page retur= ned error %d\n", errno); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0exit(-1); > + =C2=A0 =C2=A0} > + > =C2=A0 =C2=A0 /* Initialize a dummy CPU */ > =C2=A0 =C2=A0 if (cpu_model =3D=3D NULL) { > =C2=A0#ifdef TARGET_X86_64 > diff --git a/target-xen/cpu.h b/target-xen/cpu.h > index 5a45d1c..573241f 100644 > --- a/target-xen/cpu.h > +++ b/target-xen/cpu.h > @@ -72,6 +72,7 @@ typedef struct CPUXenState { > > =C2=A0CPUXenState *cpu_xen_init(const char *cpu_model); > =C2=A0int cpu_xen_exec(CPUXenState *s); > +void cpu_xen_close(CPUXenState *s); > > =C2=A0int cpu_get_pic_interrupt(CPUXenState *s); > =C2=A0void cpu_set_ferr(CPUX86State *s); > diff --git a/target-xen/helper.c b/target-xen/helper.c > index 8cb7771..4571ac0 100644 > --- a/target-xen/helper.c > +++ b/target-xen/helper.c > @@ -18,25 +18,77 @@ > =C2=A0* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA =C2=A002= 111-1307 =C2=A0USA > =C2=A0*/ > > +#include "config.h" > + > +#include > + > +#include > +#include > + > =C2=A0#include "cpu.h" > =C2=A0#include "qemu-xen.h" > =C2=A0#include "xenstore.h" > +#include "hw/xen_backend.h" > + > +long time_offset =3D 0; > + > +shared_iopage_t *shared_page =3D NULL; > + > +#define BUFFER_IO_MAX_DELAY =C2=A0100 > +buffered_iopage_t *buffered_io_page =3D NULL; > +QEMUTimer *buffered_io_timer; > + > +/* the evtchn fd for polling */ > +int xce_handle =3D -1; > + > +/* which vcpu we are serving */ > +int send_vcpu =3D 0; > + > +/* the evtchn port for polling the notification, */ > +evtchn_port_t *ioreq_local_port; > > =C2=A0CPUXenState *cpu_xen_init(const char *cpu_model) > =C2=A0{ > =C2=A0 =C2=A0 CPUXenState *env =3D NULL; > =C2=A0 =C2=A0 static int inited; > + =C2=A0 =C2=A0int i, rc; > > =C2=A0 =C2=A0 env =3D qemu_mallocz(sizeof(CPUXenState)); > =C2=A0 =C2=A0 if (!env) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL; > =C2=A0 =C2=A0 cpu_exec_init(env); > > + =C2=A0 =C2=A0/* There is no shared_page for PV, we're done now */ > + =C2=A0 =C2=A0if (shared_page =3D=3D NULL) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0return env; > + > + =C2=A0 =C2=A0ioreq_local_port =3D > + =C2=A0 =C2=A0 =C2=A0 =C2=A0(evtchn_port_t *)qemu_mallocz(smp_cpus * siz= eof(evtchn_port_t)); > + =C2=A0 =C2=A0if (!ioreq_local_port) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0return NULL; > + > =C2=A0 =C2=A0 /* init various static tables */ > =C2=A0 =C2=A0 if (!inited) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 inited =3D 1; > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 cpu_single_env =3D env; > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0xce_handle =3D xc_evtchn_open(); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (xce_handle =3D=3D -1) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0perror("open"); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return NULL; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0/* FIXME: how about if we overflow the page = here? */ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i < smp_cpus; i++) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rc =3D xc_evtchn_bind_interdom= ain( > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0xc= e_handle, xen_domid, shared_page->vcpu_ioreq[i].vp_eport); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (rc =3D=3D -1) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, = "bind interdomain ioctl error %d\n", errno); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return NULL; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ioreq_local_port[i] =3D rc; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > =C2=A0 =C2=A0 } > > =C2=A0 =C2=A0 return env; > @@ -70,7 +122,317 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState = *env, target_ulong addr) > =C2=A0 =C2=A0 return addr; > =C2=A0} > > +// get the ioreq packets from share mem > +static ioreq_t *__cpu_get_ioreq(int vcpu) Don't use names with leading underscores. > +{ > + =C2=A0 =C2=A0ioreq_t *req =3D &shared_page->vcpu_ioreq[vcpu]; > + > + =C2=A0 =C2=A0if (req->state !=3D STATE_IOREQ_READY) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "I/O request not ready: " > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"%x, ptr: %x, po= rt: %"PRIx64", " > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"data: %"PRIx64"= , count: %u, size: %u\n", > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0req->state, req-= >data_is_ptr, req->addr, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0req->data, req->= count, req->size); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0return NULL; > + =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0xen_rmb(); /* see IOREQ_READY /then/ read contents of iore= q */ > + > + =C2=A0 =C2=A0req->state =3D STATE_IOREQ_INPROCESS; > + =C2=A0 =C2=A0return req; > +} > + > +// use poll to get the port notification > +// ioreq_vec--out,the > +// retval--the number of ioreq packet > +static ioreq_t *cpu_get_ioreq(void) > +{ > + =C2=A0 =C2=A0int i; > + =C2=A0 =C2=A0evtchn_port_t port; > + > + =C2=A0 =C2=A0port =3D xc_evtchn_pending(xce_handle); > + =C2=A0 =C2=A0if (port !=3D -1) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0for ( i =3D 0; i < smp_cpus; i++ ) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if ( ioreq_local_port[i] =3D= =3D port ) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if ( i =3D=3D smp_cpus ) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "Fatal error w= hile trying to get io event!\n"); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0exit(1); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0// unmask the wanted port again > + =C2=A0 =C2=A0 =C2=A0 =C2=A0xc_evtchn_unmask(xce_handle, port); > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0// get the io packet from shared memory > + =C2=A0 =C2=A0 =C2=A0 =C2=A0send_vcpu =3D i; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0return __cpu_get_ioreq(i); > + =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0// read error or read nothing > + =C2=A0 =C2=A0return NULL; > +} > + > +static unsigned long do_inp(CPUState *env, unsigned long addr, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long size) > +{ > + =C2=A0 =C2=A0switch(size) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0case 1: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return cpu_inb(addr); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0case 2: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return cpu_inw(addr); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0case 4: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return cpu_inl(addr); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0default: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "inp: bad size= : %lx %lx\n", addr, size); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0exit(-1); > + =C2=A0 =C2=A0} > +} > + > +static void do_outp(CPUState *env, unsigned long addr, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long size, unsigned long val) > +{ > + =C2=A0 =C2=A0switch(size) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0case 1: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return cpu_outb(addr, val); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0case 2: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return cpu_outw(addr, val); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0case 4: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return cpu_outl(addr, val); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0default: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "outp: bad siz= e: %lx %lx\n", addr, size); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0exit(-1); > + =C2=A0 =C2=A0} > +} > + > +static inline void read_physical(uint64_t addr, unsigned long size, void= *val) > +{ > + =C2=A0 =C2=A0return cpu_physical_memory_rw((target_phys_addr_t)addr, va= l, size, 0); > +} > + > +static inline void write_physical(uint64_t addr, unsigned long size, voi= d *val) > +{ > + =C2=A0 =C2=A0return cpu_physical_memory_rw((target_phys_addr_t)addr, va= l, size, 1); > +} Useless redirection? > + > +static void cpu_ioreq_pio(CPUState *env, ioreq_t *req) > +{ > + =C2=A0 =C2=A0int i, sign; > + > + =C2=A0 =C2=A0sign =3D req->df ? -1 : 1; > + > + =C2=A0 =C2=A0if (req->dir =3D=3D IOREQ_READ) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!req->data_is_ptr) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0req->data =3D do_inp(env, req-= >addr, req->size); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} else { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long tmp; > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i < req->count; = i++) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tmp =3D do_inp(e= nv, req->addr, req->size); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0write_physical((= target_phys_addr_t) req->data > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0+ (sign * i * req->size), > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0req->size, &tmp); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0} else if (req->dir =3D=3D IOREQ_WRITE) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!req->data_is_ptr) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0do_outp(env, req->addr, req->s= ize, req->data); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} else { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i < req->count; = i++) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long tm= p =3D 0; > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0read_physical((t= arget_phys_addr_t) req->data > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0+ (sign * i * req->size), > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0req->size, &tmp); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0do_outp(env, req= ->addr, req->size, tmp); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0} > +} > + > +static void cpu_ioreq_move(CPUState *env, ioreq_t *req) > +{ > + =C2=A0 =C2=A0int i, sign; > + > + =C2=A0 =C2=A0sign =3D req->df ? -1 : 1; > + > + =C2=A0 =C2=A0if (!req->data_is_ptr) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (req->dir =3D=3D IOREQ_READ) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i < req->count; = i++) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0read_physical(re= q->addr > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0+ (sign * i * req->size), > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0req->size, &req->data); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} else if (req->dir =3D=3D IOREQ_WRITE) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i < req->count; = i++) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0write_physical(r= eq->addr > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0+ (sign * i * req->size), > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0req->size, &req->data); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0} else { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0target_ulong tmp; > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (req->dir =3D=3D IOREQ_READ) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i < req->count; = i++) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0read_physical(re= q->addr > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0+ (sign * i * req->size), > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0req->size, &tmp); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0write_physical((= target_phys_addr_t )req->data > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0+ (sign * i * req->size), > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0req->size, &tmp); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} else if (req->dir =3D=3D IOREQ_WRITE) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i < req->count; = i++) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0read_physical((t= arget_phys_addr_t) req->data > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0+ (sign * i * req->size), > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0req->size, &tmp); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0write_physical(r= eq->addr > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0+ (sign * i * req->size), > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0req->size, &tmp); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0} > +} > + > +static void cpu_ioreq_timeoffset(CPUState *env, ioreq_t *req) > +{ > + =C2=A0 =C2=A0char b[64]; > + > + =C2=A0 =C2=A0time_offset +=3D (unsigned long)req->data; > + > + =C2=A0 =C2=A0fprintf(stderr, "Time offset set %ld, added offset %"PRId6= 4"\n", > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0time_offset, req->data); > + =C2=A0 =C2=A0sprintf(b, "%ld", time_offset); snprintf > + =C2=A0 =C2=A0xenstore_vm_write(xen_domid, "rtc/timeoffset", b); > +} > + > +static void __handle_ioreq(CPUState *env, ioreq_t *req) > +{ > + =C2=A0 =C2=A0if (!req->data_is_ptr && (req->dir =3D=3D IOREQ_WRITE) && > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(req->size < sizeof(target_ulo= ng))) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req->data &=3D ((target_ulong)1 << (8 * req-= >size)) - 1; > + > + =C2=A0 =C2=A0switch (req->type) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0case IOREQ_TYPE_PIO: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cpu_ioreq_pio(env, req); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0case IOREQ_TYPE_COPY: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cpu_ioreq_move(env, req); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0case IOREQ_TYPE_TIMEOFFSET: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cpu_ioreq_timeoffset(env, req)= ; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0case IOREQ_TYPE_INVALIDATE: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_invalidate_map_cache(); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0default: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0hw_error("Invalid ioreq type 0= x%x\n", req->type); > + =C2=A0 =C2=A0} > +} > + > +static void __handle_buffered_iopage(CPUState *env) > +{ > + =C2=A0 =C2=A0buf_ioreq_t *buf_req =3D NULL; > + =C2=A0 =C2=A0ioreq_t req; > + =C2=A0 =C2=A0int qw; > + > + =C2=A0 =C2=A0if (!buffered_io_page) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0return; > + > + =C2=A0 =C2=A0while (buffered_io_page->read_pointer !=3D > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0buffered_io_page->write_pointe= r) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0buf_req =3D &buffered_io_page->buf_ioreq[ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0buffered_io_page->read_pointer= % IOREQ_BUFFER_SLOT_NUM]; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req.size =3D 1UL << buf_req->size; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req.count =3D 1; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req.addr =3D buf_req->addr; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req.data =3D buf_req->data; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req.state =3D STATE_IOREQ_READY; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req.dir =3D buf_req->dir; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req.df =3D 1; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req.type =3D buf_req->type; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req.data_is_ptr =3D 0; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0qw =3D (req.size =3D=3D 8); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (qw) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0buf_req =3D &buffered_io_page-= >buf_ioreq[ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(buffered_io_pag= e->read_pointer+1) % IOREQ_BUFFER_SLOT_NUM]; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0req.data |=3D ((uint64_t)buf_r= eq->data) << 32; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0__handle_ioreq(env, &req); > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0xen_mb(); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0buffered_io_page->read_pointer +=3D qw ? 2 := 1; > + =C2=A0 =C2=A0} > +} > + > +static void handle_buffered_io(void *opaque) > +{ > + =C2=A0 =C2=A0CPUState *env =3D opaque; > + > + =C2=A0 =C2=A0__handle_buffered_iopage(env); > + =C2=A0 =C2=A0qemu_mod_timer(buffered_io_timer, BUFFER_IO_MAX_DELAY + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 qemu_get= _clock(rt_clock)); > +} > + > +static void cpu_handle_ioreq(void *opaque) > +{ > + =C2=A0 =C2=A0CPUState *env =3D opaque; > + =C2=A0 =C2=A0ioreq_t *req =3D cpu_get_ioreq(); > + > + =C2=A0 =C2=A0__handle_buffered_iopage(env); > + =C2=A0 =C2=A0if (req) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0__handle_ioreq(env, req); > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (req->state !=3D STATE_IOREQ_INPROCESS) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "Badness in I/= O request ... not in service?!: " > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"%= x, ptr: %x, port: %"PRIx64", " > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"d= ata: %"PRIx64", count: %u, size: %u\n", > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0re= q->state, req->data_is_ptr, req->addr, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0re= q->data, req->count, req->size); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0destroy_hvm_domain(); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0xen_wmb(); /* Update ioreq contents /then/ u= pdate state. */ > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0req->state =3D STATE_IORESP_READY; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0xc_evtchn_notify(xce_handle, ioreq_local_por= t[send_vcpu]); > + =C2=A0 =C2=A0} > +} > + > =C2=A0void xen_main_loop_prepare(void) > =C2=A0{ > + =C2=A0 =C2=A0CPUState *env =3D cpu_single_env; > + > + =C2=A0 =C2=A0int evtchn_fd =3D xce_handle =3D=3D -1 ? -1 : xc_evtchn_fd= (xce_handle); > + > + =C2=A0 =C2=A0buffered_io_timer =3D qemu_new_timer(rt_clock, handle_buff= ered_io, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cpu_single_e= nv); > + =C2=A0 =C2=A0qemu_mod_timer(buffered_io_timer, qemu_get_clock(rt_clock)= ); > + > + =C2=A0 =C2=A0if (evtchn_fd !=3D -1) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_set_fd_handler(evtchn_fd, cpu_handle_io= req, NULL, env); > + > =C2=A0 =C2=A0 xenstore_record_dm_state("running"); > =C2=A0} > + > +void destroy_hvm_domain(void) > +{ > + =C2=A0 =C2=A0xc_interface *xcHandle; xc_handle or something. > + =C2=A0 =C2=A0int sts; > + > + =C2=A0 =C2=A0xcHandle =3D xc_interface_open(NULL, NULL, 0); > + =C2=A0 =C2=A0if (xcHandle < 0) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "Cannot acquire xenctrl hand= le\n"); > + =C2=A0 =C2=A0else { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0sts =3D xc_domain_shutdown(xcHandle, xen_dom= id, SHUTDOWN_poweroff); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (sts !=3D 0) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "? xc_domain_s= hutdown failed to issue poweroff, " > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"s= ts %d, errno %d\n", sts, errno); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0else > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "Issued domain= %d poweroff\n", xen_domid); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0xc_interface_close(xcHandle); > + =C2=A0 =C2=A0} > +} > diff --git a/target-xen/qemu-xen.h b/target-xen/qemu-xen.h > index 091ae07..79a4638 100644 > --- a/target-xen/qemu-xen.h > +++ b/target-xen/qemu-xen.h > @@ -22,12 +22,14 @@ void =C2=A0 =C2=A0 qemu_invalidate_map_cache(void); > > =C2=A0/* target-xen/exec-dm.c */ > > +void destroy_hvm_domain(void); > =C2=A0int cpu_register_io_memory_fixed(int io_index, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0CPUReadMemoryFunc * const *mem_read, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0CPUWriteMemoryFunc * const *mem_write, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0void *opaque); > > =C2=A0/* target-xen/helper.c */ > +extern int xce_handle; > =C2=A0void xen_main_loop_prepare(void); > > =C2=A0#endif /*QEMU_XEN_H*/ > -- > 1.7.0.4 > > >