mb/google/brya/var/orisa: Update Type C DisplayPort HPD Configuration
[coreboot2.git] / src / device / mmio.c
blobec9acfa72c71c729d5c7cdb06bf567ee466f747a
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <assert.h>
4 #include <commonlib/bsd/helpers.h>
5 #include <device/mmio.h>
6 #include <types.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)
13 u8 *p = buffer;
14 int i, j;
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)
29 const u8 *p = buffer;
30 int i, j = prefsz;
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);
39 write32(fifo, val);
40 val = 0;
41 j = 0;