Skip to content

Commit

Permalink
[MIPS] Always use virt_to_phys() when translating kernel addresses
Browse files Browse the repository at this point in the history
This patch fixes two places where we used plain 'x - PAGE_OFFSET' to
achieve virtual to physical address convertions. This type of convertion
is no more allowed since commit 6f284a2.

Reported-by: Maxime Bizon <[email protected]>
Signed-off-by: Franck Bui-Huu <[email protected]>

[Build fixes for machines that don't use the generic dma-coherence.h]

Signed-off-by: Ralf Baechle <[email protected]>
  • Loading branch information
fbuihuu authored and ralfbaechle committed Mar 24, 2007
1 parent f33bc55 commit c9d0696
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions arch/mips/mm/dma-default.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

#include <dma-coherence.h>

static inline unsigned long dma_addr_to_virt(dma_addr_t dma_addr)
{
unsigned long addr = plat_dma_addr_to_phys(dma_addr);

return (unsigned long)phys_to_virt(addr);
}

/*
* Warning on the terminology - Linux calls an uncached area coherent;
* MIPS terminology calls memory areas with hardware maintained coherency
Expand Down Expand Up @@ -140,7 +147,7 @@ void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
enum dma_data_direction direction)
{
if (cpu_is_noncoherent_r10000(dev))
__dma_sync(plat_dma_addr_to_phys(dma_addr) + PAGE_OFFSET, size,
__dma_sync(dma_addr_to_virt(dma_addr), size,
direction);

plat_unmap_dma_mem(dma_addr);
Expand Down Expand Up @@ -234,7 +241,7 @@ void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
if (cpu_is_noncoherent_r10000(dev)) {
unsigned long addr;

addr = PAGE_OFFSET + plat_dma_addr_to_phys(dma_handle);
addr = dma_addr_to_virt(dma_handle);
__dma_sync(addr, size, direction);
}
}
Expand All @@ -249,7 +256,7 @@ void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
if (!plat_device_is_coherent(dev)) {
unsigned long addr;

addr = PAGE_OFFSET + plat_dma_addr_to_phys(dma_handle);
addr = dma_addr_to_virt(dma_handle);
__dma_sync(addr, size, direction);
}
}
Expand All @@ -264,7 +271,7 @@ void dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
if (cpu_is_noncoherent_r10000(dev)) {
unsigned long addr;

addr = PAGE_OFFSET + plat_dma_addr_to_phys(dma_handle);
addr = dma_addr_to_virt(dma_handle);
__dma_sync(addr + offset, size, direction);
}
}
Expand All @@ -279,7 +286,7 @@ void dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
if (!plat_device_is_coherent(dev)) {
unsigned long addr;

addr = PAGE_OFFSET + plat_dma_addr_to_phys(dma_handle);
addr = dma_addr_to_virt(dma_handle);
__dma_sync(addr + offset, size, direction);
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/asm-mips/pgtable-64.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
{
return pud_val(pud);
}
#define pud_phys(pud) (pud_val(pud) - PAGE_OFFSET)
#define pud_phys(pud) virt_to_phys((void *)pud_val(pud))
#define pud_page(pud) (pfn_to_page(pud_phys(pud) >> PAGE_SHIFT))

/* Find an entry in the second-level page table.. */
Expand Down
2 changes: 1 addition & 1 deletion include/asm-mips/pgtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extern void paging_init(void);
* Conversion functions: convert a page and protection to a page entry,
* and a page entry and page directory to the page they refer to.
*/
#define pmd_phys(pmd) (pmd_val(pmd) - PAGE_OFFSET)
#define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
#define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
#define pmd_page_vaddr(pmd) pmd_val(pmd)

Expand Down

0 comments on commit c9d0696

Please sign in to comment.