blob: 74aa78d9160a04aa371a4cd2b27d7ef5b8a87b3a [file] [log] [blame]
developer02e65912023-08-17 16:33:10 +08001+=============================================================================+
2| Copyright (c) 2010-2020 Rambus, Inc. and/or its subsidiaries. |
3| |
4| Subject : DMABuf API Implementation Notes |
5| Product : SLAD API |
6| Date : 18 November, 2020 |
7| |
8+=============================================================================+
9
10SLAD API Implementation Notes : DMABuf API
11==========================================
12
13The SLAD API is a set of the API's one of which is the DMA Buffer
14Allocation (DMABuf) API. The driver implementation specifics of these APIs
15are described in short documents that serve as an addendum to the API
16specifications. This document describes the DMABuf API.
17
18
19DMABuf API
20----------
21
22The implementation of this API is fully re-entrant.
23
24Supported properties:
25 Alignment must be 1, 2, 4, 8, 16, 32, 64 or 128.
26 Bank is used to select a memory pool suitable for certain data types.
27 fCached can be used to indicate whether a DMA resource is cached.
28 Implementations of the DMAResource API can ignore the fCached parameter
29 and force all buffers to be allocated or registered either
30 cached or non-cached.
31
32DMABuf_NULLHandle:
33 Implemented as a NULL handle that can be assigned to a variable
34 of type DMABuf_Handle_t
35
36DMABuf_Handle_IsSame:
37 Two pointers to memory locations where the handles are stored
38 should be provided to this function as parameters.
39 The function will do byte comparison for the size of the handle type.
40
41DMABuf_Alloc:
42 Maximum buffer size supported is 1 megabyte.
43 Implementation uses the DMAResource API
44
45DMABuf_Register:
46 Supported values for AllocatorRef:
47 'N' to register a buffer that is not intended to be DMA-safe but for
48 which a DMABuf handle is desired nevertheless.
49 'R' to register a (subrange of) a buffer previously allocated with
50 DMABuf_Alloc. This buffer is known to be DMA-safe.
51 'k' to register a buffer allocated with Linux kmalloc.
52 'C' to register a coherent DMA-mapped buffer. The application must
53 provide the bus address in Alternative_p.
54
55 Alternative_p is only used with allocator ref 'C' and should be set to
56 "NULL" for other allocators.
57
58 All implementations of the DMAResource API support the 'N' and 'R'
59 allocators. The 'k' and 'C' allocators are only supported by
60 the Linux kernel implementation.
61
62DMABuf_Release:
63 The implementation is protected against invalid handles and also detects
64 and warns when handles are used after release (does not work well when
65 all available handles are in use).
66
67Banks:
68 The implementation supports several banks. The banks are configurable,
69 an example default configuration is as follows
70 (bank values in DMABuf_Properties_t):
71
72 - Bank 0 allocates buffers anywhere in physical RAM without restrictions.
73
74 - Bank 1 allocates buffers suitable for SA records and Transform records.
75 All these are required to lie in a single 4GB segment on 64-bit systems.
76
77 - Bank 2 allocates buffers suitable for flow records. All these are
78 required to lie in a single 4GB segment on 64-bit systems.
79
80The following properties of the static (fixed-size) DMA banks are implemented:
81
82 - One static bank contains one DMA pool;
83
84 - One DMA Pool contains a fixed compile-time configurable number of blocks;
85
86 - All blocks in one DMA pool have the same fixed compile-time configurable
87 size;
88
89 - The DMA pools for all the configured static banks are allocated
90 in DMAResource_Init() and freed in DMAResource_Uninit();
91
92 - DMA resources can be allocated in a static bank using
93 DMABuf_Alloc() and they must be freed using DMABuf_Release();
94
95 - Only sub-sets of DMA resources allocated in a static bank can be
96 registered in that bank using DMABuf_Register();
97 If the DMABuf_Register() function is called for a static
98 bank then it must use allocator type 82 ('R') and the required memory
99 block must belong to an already allocated DMA resource in that bank;
100
101 - The DMABuf_Register() function can be called for a static
102 bank also using allocator type 78 ('N') to register a DMA-unsafe buffer;
103 These DMA resources must be subsequently freed using the DMABuf_Release()
104 function;
105
106 - An "all-pool" DMA resource of size (nr_of_blocks * block_size) can be
107 allocated in a static bank using DMABuf_Alloc() where nr_of_blocks
108 and block_size are compile-time configuration parameters
109 (see HWPAL_DMARESOURCE_BANKS in c_dmares_gen.h);
110 The DMABuf_Register() function can be used to register
111 sub-sets of this DMA resource; Only one such a all-pool DMA resource
112 can be allocated in one static bank and must be freed using
113 DMABuf_Release() function;
114
115 - No other DMA resources can be allocated in a static bank
116 where an all-pool DMA resource is allocated.
117
118<end of document>