Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/xen/grant_table/grant_table.c
Show First 20 Lines • Show All 500 Lines • ▼ Show 20 Lines | unmap_pte_fn(pte_t *pte, struct page *pmd_page, | ||||
set_pte_at(&init_mm, addr, pte, __pte(0)); | set_pte_at(&init_mm, addr, pte, __pte(0)); | ||||
return 0; | return 0; | ||||
} | } | ||||
#endif | #endif | ||||
static vm_paddr_t resume_frames; | static vm_paddr_t resume_frames; | ||||
static int | static void | ||||
gnttab_map(unsigned int start_idx, unsigned int end_idx) | gnttab_map(unsigned int start_idx, unsigned int end_idx) | ||||
{ | { | ||||
struct xen_add_to_physmap xatp; | struct xen_add_to_physmap xatp; | ||||
unsigned int i = end_idx; | unsigned int i = end_idx; | ||||
/* | /* | ||||
* Loop backwards, so that the first hypercall has the largest index, | * Loop backwards, so that the first hypercall has the largest index, | ||||
* ensuring that the table will grow only once. | * ensuring that the table will grow only once. | ||||
*/ | */ | ||||
do { | do { | ||||
xatp.domid = DOMID_SELF; | xatp.domid = DOMID_SELF; | ||||
xatp.idx = i; | xatp.idx = i; | ||||
xatp.space = XENMAPSPACE_grant_table; | xatp.space = XENMAPSPACE_grant_table; | ||||
xatp.gpfn = (resume_frames >> PAGE_SHIFT) + i; | xatp.gpfn = (resume_frames >> PAGE_SHIFT) + i; | ||||
if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp)) | if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp)) | ||||
panic("HYPERVISOR_memory_op failed to map gnttab"); | panic("HYPERVISOR_memory_op failed to map gnttab"); | ||||
} while (i-- > start_idx); | } while (i-- > start_idx); | ||||
if (shared == NULL) { | |||||
vm_offset_t area; | |||||
area = kva_alloc(PAGE_SIZE * max_nr_grant_frames()); | |||||
KASSERT(area, ("can't allocate VM space for grant table")); | |||||
shared = (grant_entry_t *)area; | |||||
} | } | ||||
for (i = start_idx; i <= end_idx; i++) { | |||||
pmap_kenter((vm_offset_t) shared + i * PAGE_SIZE, | |||||
resume_frames + i * PAGE_SIZE); | |||||
} | |||||
return (0); | |||||
} | |||||
int | int | ||||
gnttab_resume(device_t dev) | gnttab_resume(device_t dev) | ||||
{ | { | ||||
unsigned int max_nr_gframes, nr_gframes; | unsigned int max_nr_gframes, nr_gframes; | ||||
nr_gframes = nr_grant_frames; | nr_gframes = nr_grant_frames; | ||||
max_nr_gframes = max_nr_grant_frames(); | max_nr_gframes = max_nr_grant_frames(); | ||||
if (max_nr_gframes < nr_gframes) | if (max_nr_gframes < nr_gframes) | ||||
return (ENOSYS); | return (ENOSYS); | ||||
if (!resume_frames) { | if (!resume_frames) { | ||||
KASSERT(dev != NULL, | KASSERT(dev != NULL, | ||||
("No resume frames and no device provided")); | ("No resume frames and no device provided")); | ||||
gnttab_pseudo_phys_res = xenmem_alloc(dev, | gnttab_pseudo_phys_res = xenmem_alloc(dev, | ||||
&gnttab_pseudo_phys_res_id, PAGE_SIZE * max_nr_gframes); | &gnttab_pseudo_phys_res_id, PAGE_SIZE * max_nr_gframes); | ||||
if (gnttab_pseudo_phys_res == NULL) | if (gnttab_pseudo_phys_res == NULL) | ||||
panic("Unable to reserve physical memory for gnttab"); | panic("Unable to reserve physical memory for gnttab"); | ||||
resume_frames = rman_get_start(gnttab_pseudo_phys_res); | resume_frames = rman_get_start(gnttab_pseudo_phys_res); | ||||
shared = rman_get_virtual(gnttab_pseudo_phys_res); | |||||
} | } | ||||
gnttab_map(0, nr_gframes - 1); | |||||
return (gnttab_map(0, nr_gframes - 1)); | return (0); | ||||
} | } | ||||
static int | static int | ||||
gnttab_expand(unsigned int req_entries) | gnttab_expand(unsigned int req_entries) | ||||
{ | { | ||||
int error; | |||||
unsigned int cur, extra; | unsigned int cur, extra; | ||||
cur = nr_grant_frames; | cur = nr_grant_frames; | ||||
extra = howmany(req_entries, GREFS_PER_GRANT_FRAME); | extra = howmany(req_entries, GREFS_PER_GRANT_FRAME); | ||||
if (cur + extra > max_nr_grant_frames()) | if (cur + extra > max_nr_grant_frames()) | ||||
return (ENOSPC); | return (ENOSPC); | ||||
error = gnttab_map(cur, cur + extra - 1); | gnttab_map(cur, cur + extra - 1); | ||||
if (!error) | |||||
error = grow_gnttab_list(extra); | |||||
return (error); | return (grow_gnttab_list(extra)); | ||||
} | } | ||||
MTX_SYSINIT(gnttab, &gnttab_list_lock, "GNTTAB LOCK", MTX_DEF | MTX_RECURSE); | MTX_SYSINIT(gnttab, &gnttab_list_lock, "GNTTAB LOCK", MTX_DEF | MTX_RECURSE); | ||||
/*------------------ Private Device Attachment Functions --------------------*/ | /*------------------ Private Device Attachment Functions --------------------*/ | ||||
/** | /** | ||||
* \brief Identify instances of this device type in the system. | * \brief Identify instances of this device type in the system. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |