--- linux/mm/memory.c.orig Mon Feb 18 14:20:52 2002 +++ linux/mm/memory.c Mon Feb 18 17:14:47 2002 @@ -1439,4 +1470,35 @@ ret = get_user_pages(current, current->mm, addr, len, write, 0, NULL, NULL); return ret == len ? 0 : -1; +} + +/* + * Given a pgd from the address space's page table, return the kernel + * virtual mapping of the physical memory mapped at addr. + */ +unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long addr) +{ + struct page *page = NULL; + pmd_t *pmd; + pte_t *ptep, pte; + + if (!pgd_none(*pgd)) { + pmd = pmd_offset(pgd, addr); + if (!pmd_none(*pmd)) { + preempt_disable(); + ptep = pte_offset_map(pmd, addr); + pte = *ptep; + if (pte_present(pte)) + page = pte_page(pte); + pte_unmap(ptep); + preempt_enable(); + } + } + /* + * This must not be used for user-space pages on + * >4GB 32-bit systems. Using this for vmalloc()-ed + * areas is safe on all systems, as long as __GFP_HIGHMEM + * is not used for the vmalloc() allocation. + */ + return (unsigned long)page_address(page); } --- linux/include/linux/mm.h.orig Mon Feb 18 14:20:49 2002 +++ linux/include/linux/mm.h Mon Feb 18 17:38:44 2002 @@ -515,6 +513,8 @@ } extern struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr); + +extern unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr); #endif /* __KERNEL__ */ --- linux/drivers/usb/pwc-if.c.orig Mon Feb 18 14:20:49 2002 +++ linux/drivers/usb/pwc-if.c Mon Feb 18 15:32:47 2002 @@ -52,6 +52,7 @@ #include #include #include +#include #include #include "pwc.h" @@ -176,37 +177,6 @@ /***************************************************************************/ /* Private functions */ - -/* Memory management functions, nicked from cpia.c, which nicked them from - bttv.c. So far, I've counted duplication of this code 6 times - (bttv, cpia, ibmcam, ov511, pwc, ieee1394). - */ - -/* Given PGD from the address space's page table, return the kernel - * virtual mapping of the physical memory mapped at ADR. - */ -static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr) -{ - unsigned long ret = 0UL; - pmd_t *pmd; - pte_t *ptep, pte; - - if (!pgd_none(*pgd)) { - pmd = pmd_offset(pgd, adr); - if (!pmd_none(*pmd)) { - ptep = pte_offset(pmd, adr); - pte = *ptep; - if(pte_present(pte)) { - ret = (unsigned long) page_address(pte_page(pte)); - ret |= (adr & (PAGE_SIZE - 1)); - - } - } - } - return ret; -} - - /* Here we want the physical address of the memory. * This is used when initializing the contents of the --- linux/drivers/usb/ov511.c.orig Mon Feb 18 14:20:49 2002 +++ linux/drivers/usb/ov511.c Mon Feb 18 15:32:19 2002 @@ -47,6 +47,7 @@ #include #include #include +#include #if defined (__i386__) #include @@ -371,48 +372,6 @@ static unsigned char uvQuanTable511[] = OV511_UVQUANTABLE; static unsigned char yQuanTable518[] = OV518_YQUANTABLE; static unsigned char uvQuanTable518[] = OV518_UVQUANTABLE; - -/********************************************************************** - * - * Memory management - * - * This is a shameless copy from the USB-cpia driver (linux kernel - * version 2.3.29 or so, I have no idea what this code actually does ;). - * Actually it seems to be a copy of a shameless copy of the bttv-driver. - * Or that is a copy of a shameless copy of ... (To the powers: is there - * no generic kernel-function to do this sort of stuff?) - * - * Yes, it was a shameless copy from the bttv-driver. IIRC, Alan says - * there will be one, but apparentely not yet -jerdfelt - * - * So I copied it again for the OV511 driver -claudio - **********************************************************************/ - -/* Given PGD from the address space's page table, return the kernel - * virtual mapping of the physical memory mapped at ADR. - */ -static inline unsigned long -uvirt_to_kva(pgd_t *pgd, unsigned long adr) -{ - unsigned long ret = 0UL; - pmd_t *pmd; - pte_t *ptep, pte; - - if (!pgd_none(*pgd)) { - pmd = pmd_offset(pgd, adr); - if (!pmd_none(*pmd)) { - ptep = pte_offset(pmd, adr); - pte = *ptep; - if (pte_present(pte)) { - ret = (unsigned long) - page_address(pte_page(pte)); - ret |= (adr & (PAGE_SIZE - 1)); - } - } - } - - return ret; -} /* Here we want the physical address of the memory. * This is used when initializing the contents of the --- linux/drivers/usb/se401.c.orig Mon Feb 18 14:20:49 2002 +++ linux/drivers/usb/se401.c Mon Feb 18 15:31:23 2002 @@ -40,6 +40,7 @@ #include #include #include +#include #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) #define virt_to_page(arg) MAP_NR(arg) @@ -80,43 +81,7 @@ * * Memory management * - * This is a shameless copy from the USB-cpia driver (linux kernel - * version 2.3.29 or so, I have no idea what this code actually does ;). - * Actually it seems to be a copy of a shameless copy of the bttv-driver. - * Or that is a copy of a shameless copy of ... (To the powers: is there - * no generic kernel-function to do this sort of stuff?) - * - * Yes, it was a shameless copy from the bttv-driver. IIRC, Alan says - * there will be one, but apparentely not yet -jerdfelt - * - * So I copied it again for the ov511 driver -claudio - * - * Same for the se401 driver -Jeroen **********************************************************************/ - -/* Given PGD from the address space's page table, return the kernel - * virtual mapping of the physical memory mapped at ADR. - */ -static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr) -{ - unsigned long ret = 0UL; - pmd_t *pmd; - pte_t *ptep, pte; - - if (!pgd_none(*pgd)) { - pmd = pmd_offset(pgd, adr); - if (!pmd_none(*pmd)) { - ptep = pte_offset(pmd, adr); - pte = *ptep; - if (pte_present(pte)) { - ret = (unsigned long) page_address(pte_page(pte)); - ret |= (adr & (PAGE_SIZE - 1)); - } - } - } - - return ret; -} /* Here we want the physical address of the memory. * This is used when initializing the contents of the --- linux/drivers/usb/usbvideo.c.orig Mon Feb 18 14:20:52 2002 +++ linux/drivers/usb/usbvideo.c Mon Feb 18 15:33:12 2002 @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -60,30 +61,6 @@ #define MDEBUG(x) do { } while(0) /* Debug memory management */ -/* Given PGD from the address space's page table, return the kernel - * virtual mapping of the physical memory mapped at ADR. - */ -unsigned long usbvideo_uvirt_to_kva(pgd_t *pgd, unsigned long adr) -{ - unsigned long ret = 0UL; - pmd_t *pmd; - pte_t *ptep, pte; - - if (!pgd_none(*pgd)) { - pmd = pmd_offset(pgd, adr); - if (!pmd_none(*pmd)) { - ptep = pte_offset(pmd, adr); - pte = *ptep; - if (pte_present(pte)) { - ret = (unsigned long) page_address(pte_page(pte)); - ret |= (adr & (PAGE_SIZE-1)); - } - } - } - MDEBUG(printk("uv2kva(%lx-->%lx)", adr, ret)); - return ret; -} - /* * Here we want the physical address of the memory. * This is used when initializing the contents of the @@ -94,7 +71,7 @@ unsigned long va, kva, ret; va = VMALLOC_VMADDR(adr); - kva = usbvideo_uvirt_to_kva(pgd_offset_k(va), va); + kva = uvirt_to_kva(pgd_offset_k(va), va); ret = __pa(kva); MDEBUG(printk("kv2pa(%lx-->%lx)", adr, ret)); return ret; --- linux/drivers/usb/usbvideo.h.orig Mon Feb 18 14:20:52 2002 +++ linux/drivers/usb/usbvideo.h Mon Feb 18 15:33:43 2002 @@ -330,7 +330,6 @@ void usbvideo_VideosizeToString(char *buf, int bufLen, videosize_t vs); /* Memory allocation routines */ -unsigned long usbvideo_uvirt_to_kva(pgd_t *pgd, unsigned long adr); unsigned long usbvideo_kvirt_to_pa(unsigned long adr); void *usbvideo_rvmalloc(unsigned long size); void usbvideo_rvfree(void *mem, unsigned long size); --- linux/drivers/ieee1394/video1394.c.orig Mon Feb 18 14:20:46 2002 +++ linux/drivers/ieee1394/video1394.c Mon Feb 18 15:31:23 2002 @@ -173,31 +173,6 @@ * defined way to get at the kernel page tables. */ -/* Given PGD from the address space's page table, return the kernel - * virtual mapping of the physical memory mapped at ADR. - */ -static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr) -{ - unsigned long ret = 0UL; - pmd_t *pmd; - pte_t *ptep, pte; - - if (!pgd_none(*pgd)) { - pmd = pmd_offset(pgd, adr); - if (!pmd_none(*pmd)) { - ptep = pte_offset(pmd, adr); - pte = *ptep; - if(pte_present(pte)) { - ret = (unsigned long) - page_address(pte_page(pte)); - ret |= (adr & (PAGE_SIZE - 1)); - } - } - } - MDEBUG(printk("uv2kva(%lx-->%lx)", adr, ret)); - return ret; -} - static inline unsigned long uvirt_to_bus(unsigned long adr) { unsigned long kva, ret; --- linux/drivers/media/video/cpia.c.orig Mon Feb 18 14:20:46 2002 +++ linux/drivers/media/video/cpia.c Mon Feb 18 15:31:23 2002 @@ -178,39 +178,7 @@ * * Memory management * - * This is a shameless copy from the USB-cpia driver (linux kernel - * version 2.3.29 or so, I have no idea what this code actually does ;). - * Actually it seems to be a copy of a shameless copy of the bttv-driver. - * Or that is a copy of a shameless copy of ... (To the powers: is there - * no generic kernel-function to do this sort of stuff?) - * - * Yes, it was a shameless copy from the bttv-driver. IIRC, Alan says - * there will be one, but apparentely not yet - jerdfelt - * **********************************************************************/ - -/* Given PGD from the address space's page table, return the kernel - * virtual mapping of the physical memory mapped at ADR. - */ -static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr) -{ - unsigned long ret = 0UL; - pmd_t *pmd; - pte_t *ptep, pte; - - if (!pgd_none(*pgd)) { - pmd = pmd_offset(pgd, adr); - if (!pmd_none(*pmd)) { - ptep = pte_offset(pmd, adr); - pte = *ptep; - if (pte_present(pte)) { - ret = (unsigned long) page_address(pte_page(pte)); - ret |= (adr & (PAGE_SIZE-1)); - } - } - } - return ret; -} /* Here we want the physical address of the memory. * This is used when initializing the contents of the --- linux/drivers/media/video/meye.c.orig Mon Feb 18 14:20:46 2002 +++ linux/drivers/media/video/meye.c Mon Feb 18 15:31:23 2002 @@ -118,30 +118,6 @@ #define MDEBUG(x) do {} while (0) /* #define MDEBUG(x) x */ -/* Given PGD from the address space's page table, return the kernel - * virtual mapping of the physical memory mapped at ADR. - */ -static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr) { - unsigned long ret = 0UL; - pmd_t *pmd; - pte_t *ptep, pte; - - if (!pgd_none(*pgd)) { - pmd = pmd_offset(pgd, adr); - if (!pmd_none(*pmd)) { - ptep = pte_offset(pmd, adr); - pte = *ptep; - if(pte_present(pte)) { - ret = (unsigned long)page_address(pte_page(pte)); - ret |= (adr & (PAGE_SIZE - 1)); - - } - } - } - MDEBUG(printk("uv2kva(%lx-->%lx)\n", adr, ret)); - return ret; -} - static inline unsigned long uvirt_to_bus(unsigned long adr) { unsigned long kva, ret; --- linux/drivers/media/video/bttv-driver.c.orig Mon Feb 18 14:20:46 2002 +++ linux/drivers/media/video/bttv-driver.c Mon Feb 18 15:31:23 2002 @@ -141,31 +141,6 @@ * defined way to get at the kernel page tables. */ -/* Given PGD from the address space's page table, return the kernel - * virtual mapping of the physical memory mapped at ADR. - */ -static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr) -{ - unsigned long ret = 0UL; - pmd_t *pmd; - pte_t *ptep, pte; - - if (!pgd_none(*pgd)) { - pmd = pmd_offset(pgd, adr); - if (!pmd_none(*pmd)) { - ptep = pte_offset(pmd, adr); - pte = *ptep; - if(pte_present(pte)) { - ret = (unsigned long) page_address(pte_page(pte)); - ret |= (adr & (PAGE_SIZE - 1)); - - } - } - } - MDEBUG(printk("uv2kva(%lx-->%lx)", adr, ret)); - return ret; -} - static inline unsigned long uvirt_to_bus(unsigned long adr) { unsigned long kva, ret;