blob: 361f62bb4a8e92efd26e3f0d91e65193085dcb3b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Joerg Roedel16489932008-10-15 22:01:03 -07002#ifndef __LINUX_SWIOTLB_H
3#define __LINUX_SWIOTLB_H
4
Thierry Reding38674442015-07-01 14:17:58 +02005#include <linux/dma-direction.h>
6#include <linux/init.h>
Joerg Roedel16489932008-10-15 22:01:03 -07007#include <linux/types.h>
8
9struct device;
Thierry Reding38674442015-07-01 14:17:58 +020010struct page;
Joerg Roedel16489932008-10-15 22:01:03 -070011struct scatterlist;
12
Geert Uytterhoevenae7871b2016-12-16 14:28:41 +010013enum swiotlb_force {
14 SWIOTLB_NORMAL, /* Default - depending on HW DMA mask etc. */
15 SWIOTLB_FORCE, /* swiotlb=force */
Geert Uytterhoevenfff5d992016-12-16 14:28:42 +010016 SWIOTLB_NO_FORCE, /* swiotlb=noforce */
Geert Uytterhoevenae7871b2016-12-16 14:28:41 +010017};
18
Ian Campbell0016fde2008-12-16 12:17:27 -080019/*
20 * Maximum allowable number of contiguous slabs to map,
21 * must be a power of 2. What is the appropriate value ?
22 * The complexity of {map,unmap}_single is linearly dependent on this value.
23 */
24#define IO_TLB_SEGSIZE 128
25
Ian Campbell0016fde2008-12-16 12:17:27 -080026/*
27 * log of the size of each IO TLB slab. The number of slabs is command line
28 * controllable.
29 */
30#define IO_TLB_SHIFT 11
31
FUJITA Tomonoriad32e8c2009-11-10 19:46:19 +090032extern void swiotlb_init(int verbose);
Yinghai Luac2cbab2013-01-24 12:20:16 -080033int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
Konrad Rzeszutek Wilkf21ffe92011-08-11 16:50:56 -040034extern unsigned long swiotlb_nr_tbl(void);
Yinghai Luc729de82013-04-15 22:23:45 -070035unsigned long swiotlb_size_or_default(void);
Konrad Rzeszutek Wilk74838b72012-07-27 20:55:27 -040036extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
Tom Lendackyc7753202017-07-17 16:10:21 -050037extern void __init swiotlb_update_mem_attributes(void);
Joerg Roedel16489932008-10-15 22:01:03 -070038
Konrad Rzeszutek Wilkd7ef1532010-05-28 11:37:10 -040039/*
40 * Enumeration for sync targets
41 */
42enum dma_sync_target {
43 SYNC_FOR_CPU = 0,
44 SYNC_FOR_DEVICE = 1,
45};
Alexander Duycke05ed4d2012-10-15 10:19:39 -070046
Alexander Duycke05ed4d2012-10-15 10:19:39 -070047extern phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
48 dma_addr_t tbl_dma_addr,
49 phys_addr_t phys, size_t size,
Alexander Duyck0443fa02016-11-02 07:13:02 -040050 enum dma_data_direction dir,
51 unsigned long attrs);
Konrad Rzeszutek Wilkd7ef1532010-05-28 11:37:10 -040052
Alexander Duyck61ca08c2012-10-15 10:19:44 -070053extern void swiotlb_tbl_unmap_single(struct device *hwdev,
54 phys_addr_t tlb_addr,
Alexander Duyck0443fa02016-11-02 07:13:02 -040055 size_t size, enum dma_data_direction dir,
56 unsigned long attrs);
Konrad Rzeszutek Wilkd7ef1532010-05-28 11:37:10 -040057
Alexander Duyckfbfda892012-10-15 10:19:49 -070058extern void swiotlb_tbl_sync_single(struct device *hwdev,
59 phys_addr_t tlb_addr,
Konrad Rzeszutek Wilkd7ef1532010-05-28 11:37:10 -040060 size_t size, enum dma_data_direction dir,
61 enum dma_sync_target target);
62
FUJITA Tomonori5740afd2009-11-10 19:46:18 +090063#ifdef CONFIG_SWIOTLB
Christoph Hellwig55897af2018-12-03 11:43:54 +010064extern enum swiotlb_force swiotlb_force;
65extern phys_addr_t io_tlb_start, io_tlb_end;
66
67static inline bool is_swiotlb_buffer(phys_addr_t paddr)
68{
69 return paddr >= io_tlb_start && paddr < io_tlb_end;
70}
71
72bool swiotlb_map(struct device *dev, phys_addr_t *phys, dma_addr_t *dma_addr,
73 size_t size, enum dma_data_direction dir, unsigned long attrs);
74void __init swiotlb_exit(void);
Konrad Rzeszutek Wilk7453c542016-12-20 10:02:02 -050075unsigned int swiotlb_max_segment(void);
Joerg Roedelabe420b2019-02-07 12:59:13 +010076size_t swiotlb_max_mapping_size(struct device *dev);
Joerg Roedel492366f2019-02-07 12:59:14 +010077bool is_swiotlb_active(void);
FUJITA Tomonori5740afd2009-11-10 19:46:18 +090078#else
Christoph Hellwig55897af2018-12-03 11:43:54 +010079#define swiotlb_force SWIOTLB_NO_FORCE
80static inline bool is_swiotlb_buffer(phys_addr_t paddr)
81{
82 return false;
83}
84static inline bool swiotlb_map(struct device *dev, phys_addr_t *phys,
85 dma_addr_t *dma_addr, size_t size, enum dma_data_direction dir,
86 unsigned long attrs)
87{
88 return false;
89}
90static inline void swiotlb_exit(void)
91{
92}
93static inline unsigned int swiotlb_max_segment(void)
94{
95 return 0;
96}
Joerg Roedelabe420b2019-02-07 12:59:13 +010097static inline size_t swiotlb_max_mapping_size(struct device *dev)
98{
99 return SIZE_MAX;
100}
Joerg Roedel492366f2019-02-07 12:59:14 +0100101
102static inline bool is_swiotlb_active(void)
103{
104 return false;
105}
Christoph Hellwig55897af2018-12-03 11:43:54 +0100106#endif /* CONFIG_SWIOTLB */
FUJITA Tomonori5740afd2009-11-10 19:46:18 +0900107
FUJITA Tomonoriad32e8c2009-11-10 19:46:19 +0900108extern void swiotlb_print_info(void);
Konrad Rzeszutek Wilk7453c542016-12-20 10:02:02 -0500109extern void swiotlb_set_max_segment(unsigned int);
Akinobu Mita9c5a3622014-06-04 16:06:50 -0700110
Joerg Roedel16489932008-10-15 22:01:03 -0700111#endif /* __LINUX_SWIOTLB_H */