mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-29 05:44:11 +00:00
swiotlb: make io_tlb_default_mem local to swiotlb.c
SWIOTLB implementation details should not be exposed to the rest of the kernel. This will allow to make changes to the implementation without modifying non-swiotlb code. To avoid breaking existing users, provide helper functions for the few required fields. As a bonus, using a helper function to initialize struct device allows to get rid of an #ifdef in driver core. Signed-off-by: Petr Tesarik <petr.tesarik.ext@huawei.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
0c6874a6ac
commit
05ee774122
6 changed files with 67 additions and 10 deletions
|
@ -664,7 +664,7 @@ static int __init octeon_pci_setup(void)
|
||||||
|
|
||||||
/* BAR1 movable regions contiguous to cover the swiotlb */
|
/* BAR1 movable regions contiguous to cover the swiotlb */
|
||||||
octeon_bar1_pci_phys =
|
octeon_bar1_pci_phys =
|
||||||
io_tlb_default_mem.start & ~((1ull << 22) - 1);
|
default_swiotlb_base() & ~((1ull << 22) - 1);
|
||||||
|
|
||||||
for (index = 0; index < 32; index++) {
|
for (index = 0; index < 32; index++) {
|
||||||
union cvmx_pci_bar1_indexx bar1_index;
|
union cvmx_pci_bar1_indexx bar1_index;
|
||||||
|
|
|
@ -3108,9 +3108,7 @@ void device_initialize(struct device *dev)
|
||||||
defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
|
defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
|
||||||
dev->dma_coherent = dma_default_coherent;
|
dev->dma_coherent = dma_default_coherent;
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_SWIOTLB
|
swiotlb_dev_init(dev);
|
||||||
dev->dma_io_tlb_mem = &io_tlb_default_mem;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(device_initialize);
|
EXPORT_SYMBOL_GPL(device_initialize);
|
||||||
|
|
||||||
|
|
|
@ -381,7 +381,7 @@ xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl,
|
||||||
static int
|
static int
|
||||||
xen_swiotlb_dma_supported(struct device *hwdev, u64 mask)
|
xen_swiotlb_dma_supported(struct device *hwdev, u64 mask)
|
||||||
{
|
{
|
||||||
return xen_phys_to_dma(hwdev, io_tlb_default_mem.end - 1) <= mask;
|
return xen_phys_to_dma(hwdev, default_swiotlb_limit()) <= mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct dma_map_ops xen_swiotlb_dma_ops = {
|
const struct dma_map_ops xen_swiotlb_dma_ops = {
|
||||||
|
|
|
@ -110,7 +110,6 @@ struct io_tlb_mem {
|
||||||
atomic_long_t used_hiwater;
|
atomic_long_t used_hiwater;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
extern struct io_tlb_mem io_tlb_default_mem;
|
|
||||||
|
|
||||||
static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
|
static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
|
||||||
{
|
{
|
||||||
|
@ -128,13 +127,22 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
|
||||||
|
|
||||||
void swiotlb_init(bool addressing_limited, unsigned int flags);
|
void swiotlb_init(bool addressing_limited, unsigned int flags);
|
||||||
void __init swiotlb_exit(void);
|
void __init swiotlb_exit(void);
|
||||||
|
void swiotlb_dev_init(struct device *dev);
|
||||||
size_t swiotlb_max_mapping_size(struct device *dev);
|
size_t swiotlb_max_mapping_size(struct device *dev);
|
||||||
|
bool is_swiotlb_allocated(void);
|
||||||
bool is_swiotlb_active(struct device *dev);
|
bool is_swiotlb_active(struct device *dev);
|
||||||
void __init swiotlb_adjust_size(unsigned long size);
|
void __init swiotlb_adjust_size(unsigned long size);
|
||||||
|
phys_addr_t default_swiotlb_base(void);
|
||||||
|
phys_addr_t default_swiotlb_limit(void);
|
||||||
#else
|
#else
|
||||||
static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
|
static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void swiotlb_dev_init(struct device *dev)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
|
static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -151,6 +159,11 @@ static inline size_t swiotlb_max_mapping_size(struct device *dev)
|
||||||
return SIZE_MAX;
|
return SIZE_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool is_swiotlb_allocated(void)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool is_swiotlb_active(struct device *dev)
|
static inline bool is_swiotlb_active(struct device *dev)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -159,6 +172,16 @@ static inline bool is_swiotlb_active(struct device *dev)
|
||||||
static inline void swiotlb_adjust_size(unsigned long size)
|
static inline void swiotlb_adjust_size(unsigned long size)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline phys_addr_t default_swiotlb_base(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline phys_addr_t default_swiotlb_limit(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif /* CONFIG_SWIOTLB */
|
#endif /* CONFIG_SWIOTLB */
|
||||||
|
|
||||||
extern void swiotlb_print_info(void);
|
extern void swiotlb_print_info(void);
|
||||||
|
|
|
@ -71,7 +71,7 @@ struct io_tlb_slot {
|
||||||
static bool swiotlb_force_bounce;
|
static bool swiotlb_force_bounce;
|
||||||
static bool swiotlb_force_disable;
|
static bool swiotlb_force_disable;
|
||||||
|
|
||||||
struct io_tlb_mem io_tlb_default_mem;
|
static struct io_tlb_mem io_tlb_default_mem;
|
||||||
|
|
||||||
static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
|
static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
|
||||||
static unsigned long default_nareas;
|
static unsigned long default_nareas;
|
||||||
|
@ -489,6 +489,15 @@ void __init swiotlb_exit(void)
|
||||||
memset(mem, 0, sizeof(*mem));
|
memset(mem, 0, sizeof(*mem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* swiotlb_dev_init() - initialize swiotlb fields in &struct device
|
||||||
|
* @dev: Device to be initialized.
|
||||||
|
*/
|
||||||
|
void swiotlb_dev_init(struct device *dev)
|
||||||
|
{
|
||||||
|
dev->dma_io_tlb_mem = &io_tlb_default_mem;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the offset into a iotlb slot required to keep the device happy.
|
* Return the offset into a iotlb slot required to keep the device happy.
|
||||||
*/
|
*/
|
||||||
|
@ -953,6 +962,14 @@ size_t swiotlb_max_mapping_size(struct device *dev)
|
||||||
return ((size_t)IO_TLB_SIZE) * IO_TLB_SEGSIZE - min_align;
|
return ((size_t)IO_TLB_SIZE) * IO_TLB_SEGSIZE - min_align;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is_swiotlb_allocated() - check if the default software IO TLB is initialized
|
||||||
|
*/
|
||||||
|
bool is_swiotlb_allocated(void)
|
||||||
|
{
|
||||||
|
return io_tlb_default_mem.nslabs;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_swiotlb_active(struct device *dev)
|
bool is_swiotlb_active(struct device *dev)
|
||||||
{
|
{
|
||||||
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
|
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
|
||||||
|
@ -960,6 +977,26 @@ bool is_swiotlb_active(struct device *dev)
|
||||||
return mem && mem->nslabs;
|
return mem && mem->nslabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default_swiotlb_base() - get the base address of the default SWIOTLB
|
||||||
|
*
|
||||||
|
* Get the lowest physical address used by the default software IO TLB pool.
|
||||||
|
*/
|
||||||
|
phys_addr_t default_swiotlb_base(void)
|
||||||
|
{
|
||||||
|
return io_tlb_default_mem.start;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default_swiotlb_limit() - get the address limit of the default SWIOTLB
|
||||||
|
*
|
||||||
|
* Get the highest physical address used by the default software IO TLB pool.
|
||||||
|
*/
|
||||||
|
phys_addr_t default_swiotlb_limit(void)
|
||||||
|
{
|
||||||
|
return io_tlb_default_mem.end - 1;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_FS
|
#ifdef CONFIG_DEBUG_FS
|
||||||
|
|
||||||
static int io_tlb_used_get(void *data, u64 *val)
|
static int io_tlb_used_get(void *data, u64 *val)
|
||||||
|
|
|
@ -864,10 +864,9 @@ void __init setup_kmalloc_cache_index_table(void)
|
||||||
|
|
||||||
static unsigned int __kmalloc_minalign(void)
|
static unsigned int __kmalloc_minalign(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC
|
if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) &&
|
||||||
if (io_tlb_default_mem.nslabs)
|
is_swiotlb_allocated())
|
||||||
return ARCH_KMALLOC_MINALIGN;
|
return ARCH_KMALLOC_MINALIGN;
|
||||||
#endif
|
|
||||||
return dma_get_cache_alignment();
|
return dma_get_cache_alignment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue