1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <commonlib/bsd/helpers.h>
5 #include <device/mmio.h>
8 /* Helper functions for various MMIO access patterns. */
10 void buffer_from_fifo32(void *buffer
, size_t size
, void *fifo
,
11 int fifo_stride
, int fifo_width
)
16 assert(fifo_width
> 0 && fifo_width
<= sizeof(u32
) &&
17 fifo_stride
% sizeof(u32
) == 0);
19 for (i
= 0; i
< size
; i
+= fifo_width
, fifo
+= fifo_stride
) {
20 u32 val
= read32(fifo
);
21 for (j
= 0; j
< MIN(size
- i
, fifo_width
); j
++)
22 *p
++ = (u8
)(val
>> (j
* 8));
26 void buffer_to_fifo32_prefix(const void *buffer
, u32 prefix
, int prefsz
, size_t size
,
27 void *fifo
, int fifo_stride
, int fifo_width
)
32 assert(fifo_width
> 0 && fifo_width
<= sizeof(u32
) &&
33 fifo_stride
% sizeof(u32
) == 0 && prefsz
<= fifo_width
);
35 uint32_t val
= prefix
;
36 for (i
= 0; i
< size
; i
+= fifo_width
, fifo
+= fifo_stride
) {
37 for (; j
< MIN(size
- i
, fifo_width
); j
++)
38 val
|= *p
++ << (j
* 8);