From patchwork Wed Mar 24 21:24:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 88070 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2OLUIwu014470 for ; Wed, 24 Mar 2010 21:30:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753539Ab0CXV3s (ORCPT ); Wed, 24 Mar 2010 17:29:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2953 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753210Ab0CXV3U (ORCPT ); Wed, 24 Mar 2010 17:29:20 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2OLTKoS015647 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 24 Mar 2010 17:29:20 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2OLTJD1028336; Wed, 24 Mar 2010 17:29:19 -0400 Received: from amt.cnet (vpn-10-46.rdu.redhat.com [10.11.10.46]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o2OLTHhA008882; Wed, 24 Mar 2010 17:29:18 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id B500B68AC69; Wed, 24 Mar 2010 18:28:14 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o2OLSDkE022415; Wed, 24 Mar 2010 18:28:13 -0300 Message-Id: <20100324212726.290507585@amt.cnet> User-Agent: quilt/0.47-1 Date: Wed, 24 Mar 2010 18:24:13 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: Marcelo Tosatti Subject: [patch 5/8] testdev: add port to create/delete memslots References: <20100324212408.790319364@amt.cnet> Content-Disposition: inline; filename=qemu-testdev-memslot X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 24 Mar 2010 21:30:19 +0000 (UTC) Index: qemu-kvm/hw/testdev.c =================================================================== --- qemu-kvm.orig/hw/testdev.c +++ qemu-kvm/hw/testdev.c @@ -5,6 +5,10 @@ struct testdev { ISADevice dev; CharDriverState *chr; + struct memslot { + target_phys_addr_t start; + target_phys_addr_t end; + } memslot; }; static void test_device_serial_write(void *opaque, uint32_t addr, uint32_t data) @@ -90,6 +94,45 @@ static CPUWriteMemoryFunc * const test_i test_iomem_writel, }; +#define CMD_CREATE_SLOT 0x0 +#define CMD_DELETE_SLOT 0x1 + +static void test_device_memslot_write(void *opaque, uint32_t addr, uint32_t data) +{ + uint32_t port = addr - 0x2018; + struct testdev *dev = opaque; + + switch(port) { + case 0: + dev->memslot.start = 0; + case 4: + dev->memslot.start |= (unsigned long)data << (port * 8); + break; + case 8: + dev->memslot.end = 0; + case 12: + dev->memslot.end |= (unsigned long)data << ((port-8) * 8); + break; + case 16: + if (data == CMD_CREATE_SLOT) { + ram_addr_t ram_addr, size; + + size = dev->memslot.end - dev->memslot.start; + + ram_addr = qemu_ram_alloc(size); + cpu_register_physical_memory(dev->memslot.start, size, ram_addr); + } + else if (data == CMD_DELETE_SLOT) { + ram_addr_t size = dev->memslot.end - dev->memslot.start; + + cpu_register_physical_memory(dev->memslot.start, size, + IO_MEM_UNASSIGNED); + } + default: + break; + } +} + static int init_test_device(ISADevice *isa) { struct testdev *dev = DO_UPCAST(struct testdev, dev, isa); @@ -105,6 +148,8 @@ static int init_test_device(ISADevice *i register_ioport_read(0xe0, 1, 4, test_device_ioport_read, dev); register_ioport_write(0xe0, 1, 4, test_device_ioport_write, dev); register_ioport_write(0x2000, 24, 1, test_device_irq_line, NULL); + register_ioport_write(0x2018, 20, 4, test_device_memslot_write, dev); + iomem_buf = qemu_mallocz(0x10000); iomem = cpu_register_io_memory(test_iomem_read, test_iomem_write, NULL); cpu_register_physical_memory(0xff000000, 0x10000, iomem);