Implement table grant mechanism for block devices Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.h Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xendisk.c Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenmem.c Modified: branches/xen/reactos/include/xen3/public/dom0_ops.h Modified: branches/xen/reactos/include/xen3/public/trace.h Modified: branches/xen/reactos/include/xen3/rosxen.h _____
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.h --- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.h 2005-04-17 17:50:48 UTC (rev 14651) +++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/machxen.h 2005-04-17 18:53:55 UTC (rev 14652) @@ -73,6 +73,7 @@
ULONG XenMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize); VOID XenMemInit(start_info_t *StartInfo); u32 XenMemVirtualToMachine(void *VirtualAddress); +int XenMemGrantForeignAccess(domid_t DomId, void *VirtAddr, BOOL ReadOnly);
BOOL XenDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); BOOL XenDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); _____
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xendisk.c --- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xendisk.c 2005-04-17 17:50:48 UTC (rev 14651) +++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xendisk.c 2005-04-17 18:53:55 UTC (rev 14652) @@ -80,6 +80,9 @@
static void *XenDiskScratchPage; static u32 XenDiskScratchMachine; +#ifdef CONFIG_XEN_BLKDEV_GRANT +static int XenDiskScratchGrantRef; +#endif /* CONFIG_XEN_BLKDEV_GRANT */
static void * XenDiskAllocatePageAlignedMemory(unsigned Size) @@ -163,8 +166,10 @@ XenEvtchnRegisterDisk(XenDiskEvtchn);
#ifdef CONFIG_XEN_BLKDEV_GRANT - rdomid = status->domid; -#endif + XenDiskScratchGrantRef = XenMemGrantForeignAccess(Status->domid, + XenDiskScratchPage, + FALSE); +#endif /* CONFIG_XEN_BLKDEV_GRANT */
XenDiskState = DISK_STATE_CONNECTED; } @@ -377,17 +382,16 @@ Req.operation = BLKIF_OP_PROBE; Req.nr_segments = 1; #ifdef CONFIG_XEN_BLKDEV_GRANT - blkif_control_probe_send(&req, &rsp, - (unsigned long)(virt_to_machine(buf))); -#else + Req.frame_and_sects[0] = (((u32) XenDiskScratchGrantRef) << 16) | 7; +#else /* CONFIG_XEN_BLKDEV_GRANT */ Req.frame_and_sects[0] = XenDiskScratchMachine | 7; +#endif /* CONFIG_XEN_BLKDEV_GRANT */
if (! XenDiskControlSend(&Req, &Rsp)) { printf("Unexpected disk disconnect\n"); XenDie(); } -#endif
if (Rsp.status <= 0) { @@ -497,16 +501,16 @@ Req.id = 0; Req.sector_number = SectorNumber; #ifdef CONFIG_XEN_BLKDEV_GRANT - blkif_control_probe_send(&req, &rsp, - (unsigned long)(virt_to_machine(buf))); -#else + Req.frame_and_sects[0] = (((u32) XenDiskScratchGrantRef) << 16) + | (Count - 1); +#else /* CONFIG_XEN_BLKDEV_GRANT */ Req.frame_and_sects[0] = XenDiskScratchMachine | (Count - 1); +#endif /* CONFIG_XEN_BLKDEV_GRANT */
if (! XenDiskControlSend(&Req, &Rsp)) { return FALSE; } -#endif if (BLKIF_RSP_OKAY != Rsp.status) { return FALSE; _____
Modified: branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenmem.c --- branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenmem.c 2005-04-17 17:50:48 UTC (rev 14651) +++ branches/xen/reactos/boot/freeldr/freeldr/arch/i386/xenmem.c 2005-04-17 18:53:55 UTC (rev 14652) @@ -23,6 +23,10 @@
#include <xen.h> #include <hypervisor.h>
+#ifdef CONFIG_XEN_BLKDEV_GRANT +#include <grant_table.h> +#endif /* CONFIG_XEN_BLKDEV_GRANT */ + /* Page Directory Entry */ typedef struct _PDE { @@ -40,9 +44,9 @@ #define PTRS_PER_PT (PAGE_SIZE / sizeof(PTE))
/* Page Directory Index of a given virtual address */ -#define PD_IDX(Va) (((Va) >> PGDIR_SHIFT) & (PTRS_PER_PD - 1)) +#define PD_IDX(Va) ((((ULONG_PTR) Va) >> PGDIR_SHIFT) & (PTRS_PER_PD - 1)) /* Page Table Index of a give virtual address */ -#define PT_IDX(Va) (((Va) >> PAGE_SHIFT) & (PTRS_PER_PT - 1)) +#define PT_IDX(Va) ((((ULONG_PTR) Va) >> PAGE_SHIFT) & (PTRS_PER_PT - 1)) /* Convert a Page Directory or Page Table entry to a (machine) address */ #define PAGE_MASK (~(PAGE_SIZE-1))
@@ -79,6 +83,10 @@ HYPERVISOR_mmu_update((req), (count), (success), (domid)) #endif /* XEN_VER */
+#ifdef CONFIG_XEN_BLKDEV_GRANT +static grant_entry_t *XenMemBlkdevGrantShared; +#endif /* CONFIG_XEN_BLKDEV_GRANT */ + ULONG XenMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize) { @@ -173,6 +181,10 @@ memory */ unsigned long PageNumber; /* Index of current page */ PPTE PageTable; /* Page table containing current page */ +#ifdef CONFIG_XEN_BLKDEV_GRANT + gnttab_setup_table_t Setup; /* Grant table setup request */ + unsigned long Frame; /* Grant table frame */ +#endif /* CONFIG_XEN_BLKDEV_GRANT */
PageDir = (PPDE) StartInfo->pt_base; PageTableForPageDir = (PPTE)((char *) StartInfo->pt_base @@ -184,8 +196,13 @@ StartPfn = ROUND_DOWN((unsigned long) &start, PAGE_SIZE) / PAGE_SIZE;
/* First, lets connect all our page tables */ +#ifdef CONFIG_XEN_BLKDEV_GRANT + PageTablesRequired = ROUND_UP(StartInfo->nr_pages + 2, PTRS_PER_PT) + / PTRS_PER_PT; +#else /* CONFIG_XEN_BLKDEV_GRANT */ PageTablesRequired = ROUND_UP(StartInfo->nr_pages + 1, PTRS_PER_PT) / PTRS_PER_PT; +#endif /* CONFIG_XEN_BLKDEV_GRANT */ for (PageTableNumber = 0; PageTableNumber < PageTablesRequired; PageTableNumber++) { @@ -306,6 +323,33 @@ HYPERVISOR_console_io(CONSOLEIO_write, sizeof(ErrMsg), ErrMsg); XenDie(); } + +#ifdef CONFIG_XEN_BLKDEV_GRANT + /* If we're using grant tables, setup a single shared grant table page + * following the shared_info page */ + Setup.dom = DOMID_SELF; + Setup.nr_frames = 1; + Setup.frame_list = &Frame; + + if (0 != HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &Setup, 1) + || 0 != Setup.status) + { + HYPERVISOR_console_io(CONSOLEIO_write, sizeof(ErrMsg), ErrMsg); + XenDie(); + } + XenMemBlkdevGrantShared = (grant_entry_t *)((XenStartInfo->nr_pages + 1) + * PAGE_SIZE); + MmuReq.ptr = (XenPageDir[PD_IDX(XenMemBlkdevGrantShared)].Pde + & PAGE_MASK) + + PT_IDX(XenMemBlkdevGrantShared) * sizeof(PTE); + MmuReq.val = (Frame << PAGE_SHIFT) + | (PA_PRESENT | PA_READWRITE | PA_USER); + if (0 != XEN_MMU_UPDATE(&MmuReq, 1, NULL, DOMID_SELF)) + { + HYPERVISOR_console_io(CONSOLEIO_write, sizeof(ErrMsg), ErrMsg); + XenDie(); + } +#endif /* CONFIG_XEN_BLKDEV_GRANT */ }
u32 @@ -319,4 +363,21 @@ & PAGE_MASK; }
+#ifdef CONFIG_XEN_BLKDEV_GRANT +int +XenMemGrantForeignAccess(domid_t DomId, void *VirtualAddress, BOOL ReadOnly) +{ + int Ref = 0; /* We only do 1 page at the moment */ + + XenMemBlkdevGrantShared[Ref].frame = (XenMemVirtualToMachine(VirtualAddress) + >> PAGE_SHIFT); + XenMemBlkdevGrantShared[Ref].domid = DomId; + wmb(); + XenMemBlkdevGrantShared[Ref].flags = GTF_permit_access + | (ReadOnly ? GTF_readonly : 0); + + return Ref; +} +#endif /* CONFIG_XEN_BLKDEV_GRANT */ + /* EOF */ _____
Modified: branches/xen/reactos/include/xen3/public/dom0_ops.h --- branches/xen/reactos/include/xen3/public/dom0_ops.h 2005-04-17 17:50:48 UTC (rev 14651) +++ branches/xen/reactos/include/xen3/public/dom0_ops.h 2005-04-17 18:53:55 UTC (rev 14652) @@ -242,6 +242,7 @@
#define DOM0_SHADOW_CONTROL_OP_OFF 0 #define DOM0_SHADOW_CONTROL_OP_ENABLE_TEST 1 #define DOM0_SHADOW_CONTROL_OP_ENABLE_LOGDIRTY 2 +#define DOM0_SHADOW_CONTROL_OP_ENABLE_TRANSLATE 3
#define DOM0_SHADOW_CONTROL_OP_FLUSH 10 /* table ops */ #define DOM0_SHADOW_CONTROL_OP_CLEAN 11 _____
Modified: branches/xen/reactos/include/xen3/public/trace.h --- branches/xen/reactos/include/xen3/public/trace.h 2005-04-17 17:50:48 UTC (rev 14651) +++ branches/xen/reactos/include/xen3/public/trace.h 2005-04-17 18:53:55 UTC (rev 14652) @@ -8,8 +8,6 @@
#ifndef __XEN_PUBLIC_TRACE_H__ #define __XEN_PUBLIC_TRACE_H__
-#include <asm/atomic.h> - /* Trace classes */ #define TRC_GEN 0x00010000 /* General trace */ #define TRC_SCHED 0x00020000 /* Xen Scheduler trace */ _____
Modified: branches/xen/reactos/include/xen3/rosxen.h --- branches/xen/reactos/include/xen3/rosxen.h 2005-04-17 17:50:48 UTC (rev 14651) +++ branches/xen/reactos/include/xen3/rosxen.h 2005-04-17 18:53:55 UTC (rev 14652) @@ -5,6 +5,9 @@
#ifndef ROSXEN_H_INCLUDED #define ROSXEN_H_INCLUDED
+/* Match this with your dom0 Linux .config */ +#define CONFIG_XEN_BLKDEV_GRANT + typedef unsigned char u8; typedef unsigned short u16; typedef unsigned long u32;