]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/swiotlb.h
Merge tag 'fs.move_mount.move_mount_set_group.v5.15' of git://git.kernel.org/pub...
[mirror_ubuntu-jammy-kernel.git] / include / linux / swiotlb.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1648993f
JR
2#ifndef __LINUX_SWIOTLB_H
3#define __LINUX_SWIOTLB_H
4
38674442
TR
5#include <linux/dma-direction.h>
6#include <linux/init.h>
1648993f 7#include <linux/types.h>
f51778db 8#include <linux/limits.h>
73f62095 9#include <linux/spinlock.h>
1648993f
JR
10
11struct device;
38674442 12struct page;
1648993f
JR
13struct scatterlist;
14
ae7871be
GU
15enum swiotlb_force {
16 SWIOTLB_NORMAL, /* Default - depending on HW DMA mask etc. */
17 SWIOTLB_FORCE, /* swiotlb=force */
fff5d992 18 SWIOTLB_NO_FORCE, /* swiotlb=noforce */
ae7871be
GU
19};
20
0016fdee
IC
21/*
22 * Maximum allowable number of contiguous slabs to map,
23 * must be a power of 2. What is the appropriate value ?
24 * The complexity of {map,unmap}_single is linearly dependent on this value.
25 */
26#define IO_TLB_SEGSIZE 128
27
0016fdee
IC
28/*
29 * log of the size of each IO TLB slab. The number of slabs is command line
30 * controllable.
31 */
32#define IO_TLB_SHIFT 11
b5d7ccb7 33#define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
0016fdee 34
e998879d
AK
35/* default to 64MB */
36#define IO_TLB_DEFAULT_SIZE (64UL<<20)
37
ad32e8cb 38extern void swiotlb_init(int verbose);
ac2cbab2 39int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
c729de8f 40unsigned long swiotlb_size_or_default(void);
74838b75 41extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
61b82bbf 42extern int swiotlb_late_init_with_default_size(size_t default_size);
c7753208 43extern void __init swiotlb_update_mem_attributes(void);
1648993f 44
fc0021aa
CH
45phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
46 size_t mapping_size, size_t alloc_size,
47 enum dma_data_direction dir, unsigned long attrs);
d7ef1533 48
61ca08c3
AD
49extern void swiotlb_tbl_unmap_single(struct device *hwdev,
50 phys_addr_t tlb_addr,
3fc1ca00 51 size_t mapping_size,
3fc1ca00 52 enum dma_data_direction dir,
0443fa00 53 unsigned long attrs);
d7ef1533 54
80808d27
CH
55void swiotlb_sync_single_for_device(struct device *dev, phys_addr_t tlb_addr,
56 size_t size, enum dma_data_direction dir);
57void swiotlb_sync_single_for_cpu(struct device *dev, phys_addr_t tlb_addr,
58 size_t size, enum dma_data_direction dir);
4a47cbae
CH
59dma_addr_t swiotlb_map(struct device *dev, phys_addr_t phys,
60 size_t size, enum dma_data_direction dir, unsigned long attrs);
61
5740afdb 62#ifdef CONFIG_SWIOTLB
55897af6 63extern enum swiotlb_force swiotlb_force;
73f62095
CC
64
65/**
66 * struct io_tlb_mem - IO TLB Memory Pool Descriptor
67 *
68 * @start: The start address of the swiotlb memory pool. Used to do a quick
69 * range check to see if the memory was in fact allocated by this
70 * API.
71 * @end: The end address of the swiotlb memory pool. Used to do a quick
72 * range check to see if the memory was in fact allocated by this
73 * API.
74 * @nslabs: The number of IO TLB blocks (in groups of 64) between @start and
75 * @end. This is command line adjustable via setup_io_tlb_npages.
76 * @used: The number of used IO TLB block.
77 * @list: The free list describing the number of free entries available
78 * from each index.
79 * @index: The index to start searching in the next round.
80 * @orig_addr: The original address corresponding to a mapped entry.
81 * @alloc_size: Size of the allocated buffer.
82 * @lock: The lock to protect the above data structures in the map and
83 * unmap calls.
84 * @debugfs: The dentry to debugfs.
85 * @late_alloc: %true if allocated using the page allocator
86 */
87struct io_tlb_mem {
88 phys_addr_t start;
89 phys_addr_t end;
90 unsigned long nslabs;
91 unsigned long used;
73f62095 92 unsigned int index;
73f62095
CC
93 spinlock_t lock;
94 struct dentry *debugfs;
95 bool late_alloc;
2d29960a
CH
96 struct io_tlb_slot {
97 phys_addr_t orig_addr;
98 size_t alloc_size;
99 unsigned int list;
100 } slots[];
73f62095 101};
2d29960a 102extern struct io_tlb_mem *io_tlb_default_mem;
55897af6
CH
103
104static inline bool is_swiotlb_buffer(phys_addr_t paddr)
105{
2d29960a 106 struct io_tlb_mem *mem = io_tlb_default_mem;
73f62095 107
2d29960a 108 return mem && paddr >= mem->start && paddr < mem->end;
55897af6
CH
109}
110
55897af6 111void __init swiotlb_exit(void);
7453c549 112unsigned int swiotlb_max_segment(void);
abe420bf 113size_t swiotlb_max_mapping_size(struct device *dev);
492366f7 114bool is_swiotlb_active(void);
2d29960a 115void __init swiotlb_adjust_size(unsigned long size);
5740afdb 116#else
55897af6
CH
117#define swiotlb_force SWIOTLB_NO_FORCE
118static inline bool is_swiotlb_buffer(phys_addr_t paddr)
119{
120 return false;
121}
55897af6
CH
122static inline void swiotlb_exit(void)
123{
124}
125static inline unsigned int swiotlb_max_segment(void)
126{
127 return 0;
128}
abe420bf
JR
129static inline size_t swiotlb_max_mapping_size(struct device *dev)
130{
131 return SIZE_MAX;
132}
492366f7
JR
133
134static inline bool is_swiotlb_active(void)
135{
136 return false;
137}
e998879d 138
2d29960a 139static inline void swiotlb_adjust_size(unsigned long size)
e998879d
AK
140{
141}
55897af6 142#endif /* CONFIG_SWIOTLB */
5740afdb 143
ad32e8cb 144extern void swiotlb_print_info(void);
7453c549 145extern void swiotlb_set_max_segment(unsigned int);
9c5a3621 146
1648993f 147#endif /* __LINUX_SWIOTLB_H */