1.1 --- a/pkg/devices/lib/msc/src/common.cc Wed Feb 21 00:33:55 2024 +0100
1.2 +++ b/pkg/devices/lib/msc/src/common.cc Fri Feb 23 22:52:35 2024 +0100
1.3 @@ -21,8 +21,12 @@
1.4
1.5 #include <l4/devices/hw_mmio_register_block.h>
1.6 #include <l4/sys/irq.h>
1.7 +#include <l4/sys/rcv_endpoint.h>
1.8 #include <l4/util/util.h>
1.9
1.10 +#include <pthread.h>
1.11 +#include <pthread-l4.h>
1.12 +
1.13 #include <math.h>
1.14 #include <stdio.h>
1.15
1.16 @@ -445,6 +449,9 @@
1.17 bool
1.18 Msc_channel::wait_for_irq(uint32_t flags)
1.19 {
1.20 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
1.21 + return false;
1.22 +
1.23 return !l4_error(l4_irq_receive(_irq, L4_IPC_NEVER)) &&
1.24 (_regs[Msc_interrupt_flag] & flags);
1.25 }
1.26 @@ -455,6 +462,9 @@
1.27 bool
1.28 Msc_channel::wait_for_irq(uint32_t flags, unsigned int timeout)
1.29 {
1.30 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
1.31 + return false;
1.32 +
1.33 return !l4_error(l4_irq_receive(_irq, l4_timeout(L4_IPC_TIMEOUT_NEVER,
1.34 l4util_micros2l4to(timeout)))) &&
1.35 (_regs[Msc_interrupt_flag] & flags);
1.36 @@ -798,6 +808,26 @@
1.37 return to_transfer;
1.38 }
1.39
1.40 +// Read data from the indicated card into a memory region.
1.41 +
1.42 +uint32_t
1.43 +Msc_channel::read(uint8_t card, struct dma_region *region,
1.44 + uint32_t address, uint32_t count)
1.45 +{
1.46 + uint32_t block_size = 1 << _cards[card].csd.read_blocklen;
1.47 +
1.48 + // Obtain the block address from the byte address and the number of blocks
1.49 + // from the byte count.
1.50 +
1.51 + // NOTE: Rejecting addresses and counts that are not multiples of the block
1.52 + // NOTE: size. Should produce an error.
1.53 +
1.54 + if ((address % block_size) || (count % block_size))
1.55 + return 0;
1.56 +
1.57 + return read_blocks(card, region, address / block_size, count / block_size);
1.58 +}
1.59 +
1.60 // Read blocks from the indicated card into a memory region.
1.61
1.62 uint32_t