Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/src/linux_page.c
Show All 33 Lines | |||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/rwlock.h> | #include <sys/rwlock.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <sys/sched.h> | #include <sys/sched.h> | ||||
#include <sys/sf_buf.h> | |||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <vm/vm.h> | #include <vm/vm.h> | ||||
#include <vm/pmap.h> | #include <vm/pmap.h> | ||||
#include <vm/vm_param.h> | #include <vm/vm_param.h> | ||||
#include <vm/vm_kern.h> | #include <vm/vm_kern.h> | ||||
#include <vm/vm_object.h> | #include <vm/vm_object.h> | ||||
#include <vm/vm_map.h> | #include <vm/vm_map.h> | ||||
#include <vm/vm_page.h> | #include <vm/vm_page.h> | ||||
#include <vm/vm_pageout.h> | #include <vm/vm_pageout.h> | ||||
#include <vm/vm_pager.h> | #include <vm/vm_pager.h> | ||||
#include <vm/vm_radix.h> | #include <vm/vm_radix.h> | ||||
#include <vm/vm_reserv.h> | #include <vm/vm_reserv.h> | ||||
#include <vm/vm_extern.h> | #include <vm/vm_extern.h> | ||||
#include <vm/uma.h> | #include <vm/uma.h> | ||||
#include <vm/uma_int.h> | #include <vm/uma_int.h> | ||||
#include <linux/gfp.h> | #include <linux/gfp.h> | ||||
#include <linux/highmem.h> | |||||
#include <linux/mm.h> | #include <linux/mm.h> | ||||
#include <linux/preempt.h> | #include <linux/preempt.h> | ||||
#include <linux/fs.h> | #include <linux/fs.h> | ||||
#include <linux/shmem_fs.h> | #include <linux/shmem_fs.h> | ||||
#if defined(__LP64__) | |||||
#define LINUXKPI_HAVE_DMAP | |||||
#else | |||||
#undef LINUXKPI_HAVE_DMAP | |||||
#endif | |||||
bz: Is this PMAP_HAS_DMAP now? | |||||
wulfAuthorUnsubmitted Done Inline ActionsLooks like that wulf: Looks like that | |||||
void | void | ||||
si_meminfo(struct sysinfo *si) | si_meminfo(struct sysinfo *si) | ||||
{ | { | ||||
si->totalram = physmem; | si->totalram = physmem; | ||||
si->totalhigh = 0; | si->totalhigh = 0; | ||||
si->mem_unit = PAGE_SIZE; | si->mem_unit = PAGE_SIZE; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | if (vm_page_insert(page, vm_obj, pindex)) { | ||||
return (VM_FAULT_OOM); | return (VM_FAULT_OOM); | ||||
} | } | ||||
vm_page_valid(page); | vm_page_valid(page); | ||||
} | } | ||||
pmap_page_set_memattr(page, pgprot2cachemode(prot)); | pmap_page_set_memattr(page, pgprot2cachemode(prot)); | ||||
vma->vm_pfn_count++; | vma->vm_pfn_count++; | ||||
return (VM_FAULT_NOPAGE); | return (VM_FAULT_NOPAGE); | ||||
} | |||||
void * | |||||
lkpi_kmap(vm_page_t page) | |||||
{ | |||||
#ifdef LINUXKPI_HAVE_DMAP | |||||
vm_offset_t daddr; | |||||
daddr = PHYS_TO_DMAP(VM_PAGE_TO_PHYS(page)); | |||||
return ((void *)daddr); | |||||
#else | |||||
struct sf_buf *sf; | |||||
sched_pin(); | |||||
sf = sf_buf_alloc(page, SFB_NOWAIT | SFB_CPUPRIVATE); | |||||
if (sf == NULL) { | |||||
Not Done Inline ActionsWe always start at pindex 0, so holebegin is ignored. I understand that this may provide the desired semantics (or is it a bug?) but it looks wrong and deserves a comment IMHO. markj: We always start at pindex 0, so `holebegin` is ignored. I understand that this may provide the… | |||||
sched_unpin(); | |||||
return (NULL); | |||||
} | |||||
return ((void *)sf_buf_kva(sf)); | |||||
#endif | |||||
} | |||||
void * | |||||
lkpi_kmap_atomic_prot(vm_page_t page, pgprot_t prot) | |||||
Not Done Inline ActionsWhich vm_object_reference() call does this pair with? markj: Which vm_object_reference() call does this pair with? | |||||
Done Inline ActionsIt lies in linux_file_mmap_single() in sys/compat/linuxkpi/common/src/linux_compat.c (through cdev_pager_allocate() call). This routine is destructor for it. wulf: It lies in linux_file_mmap_single() in `sys/compat/linuxkpi/common/src/linux_compat.c` (through… | |||||
{ | |||||
vm_memattr_t attr = pgprot2cachemode(prot); | |||||
if (attr != VM_MEMATTR_DEFAULT) { | |||||
vm_page_lock(page); | |||||
page->flags |= PG_FICTITIOUS; | |||||
vm_page_unlock(page); | |||||
pmap_page_set_memattr(page, attr); | |||||
} | |||||
return (kmap(page)); | |||||
} | |||||
void | |||||
lkpi_kunmap(vm_page_t page) | |||||
{ | |||||
#ifdef LINUXKPI_HAVE_DMAP | |||||
/* NOP */ | |||||
#else | |||||
struct sf_buf *sf; | |||||
/* lookup SF buffer in list */ | |||||
sf = sf_buf_alloc(page, SFB_NOWAIT | SFB_CPUPRIVATE); | |||||
/* double-free */ | |||||
sf_buf_free(sf); | |||||
sf_buf_free(sf); | |||||
sched_unpin(); | |||||
#endif | |||||
} | |||||
void | |||||
lkpi_kunmap_atomic(void *vaddr) | |||||
{ | |||||
#ifdef LINUXKPI_HAVE_DMAP | |||||
/* NOP */ | |||||
#else | |||||
struct sf_buf *sf; | |||||
vm_page_t page; | |||||
page = virt_to_page(vaddr); | |||||
/* lookup SF buffer in list */ | |||||
sf = sf_buf_alloc(page, SFB_NOWAIT | SFB_CPUPRIVATE); | |||||
/* double-free */ | |||||
sf_buf_free(sf); | |||||
sf_buf_free(sf); | |||||
sched_unpin(); | |||||
#endif | |||||
} | |||||
void | |||||
lkpi_unmap_mapping_range(void *obj, loff_t const holebegin, | |||||
loff_t const holelen, int even_cows) | |||||
{ | |||||
vm_object_t devobj; | |||||
vm_page_t page; | |||||
int i, page_count; | |||||
#ifdef LINUX_VERBOSE_DEBUG | |||||
kdb_backtrace(); | |||||
printf("unmap_mapping_range: obj: %p holebegin %zu, holelen: %zu, " | |||||
bzUnsubmitted Done Inline ActionsProbably %s: func better here now or rather remove this entirely as we don't have a LINUX_VERBOSE_DEBUG? bz: Probably %s: __func__ better here now or rather remove this entirely as we don't have a… | |||||
wulfAuthorUnsubmitted Done Inline Actions
debugging stuff removed wulf: > Probably %s: __func__ better here now or rather remove this entirely as we don't have a… | |||||
"even_cows: %d\n", obj, holebegin, holelen, even_cows); | |||||
#endif | |||||
devobj = cdev_pager_lookup(obj); | |||||
if (devobj != NULL) { | |||||
page_count = OFF_TO_IDX(holelen); | |||||
VM_OBJECT_WLOCK(devobj); | |||||
retry: | |||||
for (i = 0; i < page_count; i++) { | |||||
page = vm_page_lookup(devobj, i); | |||||
if (page == NULL) | |||||
continue; | |||||
if (!vm_page_busy_acquire(page, VM_ALLOC_WAITFAIL)) | |||||
goto retry; | |||||
cdev_pager_free_page(devobj, page); | |||||
} | |||||
VM_OBJECT_WUNLOCK(devobj); | |||||
vm_object_deallocate(devobj); | |||||
} | |||||
} | } |
Is this PMAP_HAS_DMAP now?