summaryrefslogtreecommitdiff
path: root/arch/s390/include/asm/dma-types.h
blob: 5c5734e6946c0ecb0b8fa81a00a92ba9e18cf35d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* SPDX-License-Identifier: GPL-2.0 */

#ifndef _ASM_S390_DMA_TYPES_H_
#define _ASM_S390_DMA_TYPES_H_

#include <linux/types.h>
#include <linux/io.h>

/*
 * typedef dma32_t
 * Contains a 31 bit absolute address to a DMA capable piece of storage.
 *
 * For CIO, DMA addresses are always absolute addresses. These addresses tend
 * to be used in architectured memory blocks (like ORB, IDAW, MIDAW). Under
 * certain circumstances 31 bit wide addresses must be used because the
 * address must fit in 31 bits.
 *
 * This type is to be used when such fields can be modelled as 32 bit wide.
 */
typedef u32 __bitwise dma32_t;

/*
 * typedef dma64_t
 * Contains a 64 bit absolute address to a DMA capable piece of storage.
 *
 * For CIO, DMA addresses are always absolute addresses. These addresses tend
 * to be used in architectured memory blocks (like ORB, IDAW, MIDAW).
 *
 * This type is to be used to model such 64 bit wide fields.
 */
typedef u64 __bitwise dma64_t;

/*
 * Although DMA addresses should be obtained using the DMA API, in cases when
 * it is known that the first argument holds a virtual address that points to
 * DMA-able 31 bit addressable storage, then this function can be safely used.
 */
static inline dma32_t virt_to_dma32(void *ptr)
{
	return (__force dma32_t)__pa32(ptr);
}

static inline void *dma32_to_virt(dma32_t addr)
{
	return __va((__force unsigned long)addr);
}

static inline dma32_t u32_to_dma32(u32 addr)
{
	return (__force dma32_t)addr;
}

static inline u32 dma32_to_u32(dma32_t addr)
{
	return (__force u32)addr;
}

static inline dma32_t dma32_add(dma32_t a, u32 b)
{
	return (__force dma32_t)((__force u32)a + b);
}

static inline dma32_t dma32_and(dma32_t a, u32 b)
{
	return (__force dma32_t)((__force u32)a & b);
}

/*
 * Although DMA addresses should be obtained using the DMA API, in cases when
 * it is known that the first argument holds a virtual address that points to
 * DMA-able storage, then this function can be safely used.
 */
static inline dma64_t virt_to_dma64(void *ptr)
{
	return (__force dma64_t)__pa(ptr);
}

static inline void *dma64_to_virt(dma64_t addr)
{
	return __va((__force unsigned long)addr);
}

static inline dma64_t u64_to_dma64(u64 addr)
{
	return (__force dma64_t)addr;
}

static inline u64 dma64_to_u64(dma64_t addr)
{
	return (__force u64)addr;
}

static inline dma64_t dma64_add(dma64_t a, u64 b)
{
	return (__force dma64_t)((__force u64)a + b);
}

static inline dma64_t dma64_and(dma64_t a, u64 b)
{
	return (__force dma64_t)((__force u64)a & b);
}

#endif /* _ASM_S390_DMA_TYPES_H_ */