/*1* ioremap.c2*3* Support for mapping between dma_addr_t values a phys_addr_t values.4*5* Copyright (C) 2005-2009 Scientific-Atlanta, Inc.6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA20*21* Author: David VomLehn <[email protected]>22*23* Description: Defines the platform resources for the SA settop.24*25* NOTE: The bootloader allocates persistent memory at an address which is26* 16 MiB below the end of the highest address in KSEG0. All fixed27* address memory reservations must avoid this region.28*/2930#include <linux/kernel.h>31#include <linux/module.h>3233#include <asm/mach-powertv/ioremap.h>3435/*36* Define the sizes of and masks for grains in physical and DMA space. The37* values are the same but the types are not.38*/39#define IOR_PHYS_GRAIN ((phys_addr_t) 1 << IOR_LSBITS)40#define IOR_PHYS_GRAIN_MASK (IOR_PHYS_GRAIN - 1)4142#define IOR_DMA_GRAIN ((dma_addr_t) 1 << IOR_LSBITS)43#define IOR_DMA_GRAIN_MASK (IOR_DMA_GRAIN - 1)4445/*46* Values that, when accessed by an index derived from a phys_addr_t and47* added to phys_addr_t value, yield a DMA address48*/49struct ior_phys_to_dma _ior_phys_to_dma[IOR_NUM_PHYS_TO_DMA];50EXPORT_SYMBOL(_ior_phys_to_dma);5152/*53* Values that, when accessed by an index derived from a dma_addr_t and54* added to that dma_addr_t value, yield a physical address55*/56struct ior_dma_to_phys _ior_dma_to_phys[IOR_NUM_DMA_TO_PHYS];57EXPORT_SYMBOL(_ior_dma_to_phys);5859/**60* setup_dma_to_phys - set up conversion from DMA to physical addresses61* @dma_idx: Top IOR_LSBITS bits of the DMA address, i.e. an index62* into the array _dma_to_phys.63* @delta: Value that, when added to the DMA address, will yield the64* physical address65* @s: Number of bytes in the section of memory with the given delta66* between DMA and physical addresses.67*/68static void setup_dma_to_phys(dma_addr_t dma, phys_addr_t delta, dma_addr_t s)69{70int dma_idx, first_idx, last_idx;71phys_addr_t first, last;7273/*74* Calculate the first and last indices, rounding the first up and75* the second down.76*/77first = dma & ~IOR_DMA_GRAIN_MASK;78last = (dma + s - 1) & ~IOR_DMA_GRAIN_MASK;79first_idx = first >> IOR_LSBITS; /* Convert to indices */80last_idx = last >> IOR_LSBITS;8182for (dma_idx = first_idx; dma_idx <= last_idx; dma_idx++)83_ior_dma_to_phys[dma_idx].offset = delta >> IOR_DMA_SHIFT;84}8586/**87* setup_phys_to_dma - set up conversion from DMA to physical addresses88* @phys_idx: Top IOR_LSBITS bits of the DMA address, i.e. an index89* into the array _phys_to_dma.90* @delta: Value that, when added to the DMA address, will yield the91* physical address92* @s: Number of bytes in the section of memory with the given delta93* between DMA and physical addresses.94*/95static void setup_phys_to_dma(phys_addr_t phys, dma_addr_t delta, phys_addr_t s)96{97int phys_idx, first_idx, last_idx;98phys_addr_t first, last;99100/*101* Calculate the first and last indices, rounding the first up and102* the second down.103*/104first = phys & ~IOR_PHYS_GRAIN_MASK;105last = (phys + s - 1) & ~IOR_PHYS_GRAIN_MASK;106first_idx = first >> IOR_LSBITS; /* Convert to indices */107last_idx = last >> IOR_LSBITS;108109for (phys_idx = first_idx; phys_idx <= last_idx; phys_idx++)110_ior_phys_to_dma[phys_idx].offset = delta >> IOR_PHYS_SHIFT;111}112113/**114* ioremap_add_map - add to the physical and DMA address conversion arrays115* @phys: Process's view of the address of the start of the memory chunk116* @dma: DMA address of the start of the memory chunk117* @size: Size, in bytes, of the chunk of memory118*119* NOTE: It might be obvious, but the assumption is that all @size bytes have120* the same offset between the physical address and the DMA address.121*/122void ioremap_add_map(phys_addr_t phys, phys_addr_t dma, phys_addr_t size)123{124if (size == 0)125return;126127if ((dma & IOR_DMA_GRAIN_MASK) != 0 ||128(phys & IOR_PHYS_GRAIN_MASK) != 0 ||129(size & IOR_PHYS_GRAIN_MASK) != 0)130pr_crit("Memory allocation must be in chunks of 0x%x bytes\n",131IOR_PHYS_GRAIN);132133setup_dma_to_phys(dma, phys - dma, size);134setup_phys_to_dma(phys, dma - phys, size);135}136137138