1.1 --- a/pkg/devices/lib/dma/src/jz4730.cc Wed Feb 21 00:33:55 2024 +0100
1.2 +++ b/pkg/devices/lib/dma/src/jz4730.cc Fri Feb 23 22:52:35 2024 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * DMA support for the JZ4730.
1.6 *
1.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2021, 2024 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -22,11 +22,14 @@
1.13 #include <l4/devices/dma-jz4730.h>
1.14 #include <l4/devices/hw_mmio_register_block.h>
1.15
1.16 -#include <l4/sys/icu.h>
1.17 #include <l4/sys/ipc.h>
1.18 #include <l4/sys/irq.h>
1.19 +#include <l4/sys/rcv_endpoint.h>
1.20 #include <l4/util/util.h>
1.21
1.22 +#include <pthread.h>
1.23 +#include <pthread-l4.h>
1.24 +
1.25 #include <stdio.h>
1.26
1.27
1.28 @@ -336,6 +339,9 @@
1.29 bool
1.30 Dma_jz4730_channel::wait_for_irq()
1.31 {
1.32 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
1.33 + return false;
1.34 +
1.35 return !l4_error(l4_irq_receive(_irq, L4_IPC_NEVER)) && _chip->have_interrupt(_channel);
1.36 }
1.37
1.38 @@ -345,6 +351,9 @@
1.39 bool
1.40 Dma_jz4730_channel::wait_for_irq(unsigned int timeout)
1.41 {
1.42 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
1.43 + return false;
1.44 +
1.45 return !l4_error(l4_irq_receive(_irq, l4_timeout(L4_IPC_TIMEOUT_NEVER, l4util_micros2l4to(timeout)))) && _chip->have_interrupt(_channel);
1.46 }
1.47
2.1 --- a/pkg/devices/lib/dma/src/jz4780.cc Wed Feb 21 00:33:55 2024 +0100
2.2 +++ b/pkg/devices/lib/dma/src/jz4780.cc Fri Feb 23 22:52:35 2024 +0100
2.3 @@ -24,11 +24,14 @@
2.4 #include <l4/devices/hw_mmio_register_block.h>
2.5
2.6 #include <l4/sys/cache.h>
2.7 -#include <l4/sys/icu.h>
2.8 #include <l4/sys/ipc.h>
2.9 #include <l4/sys/irq.h>
2.10 +#include <l4/sys/rcv_endpoint.h>
2.11 #include <l4/util/util.h>
2.12
2.13 +#include <pthread.h>
2.14 +#include <pthread-l4.h>
2.15 +
2.16 #include <stdio.h>
2.17
2.18
2.19 @@ -394,7 +397,12 @@
2.20 Dma_jz4780_channel::wait_for_irq()
2.21 {
2.22 if (l4_is_valid_cap(_irq))
2.23 + {
2.24 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
2.25 + return false;
2.26 +
2.27 return !l4_error(l4_irq_receive(_irq, L4_IPC_NEVER)) && _chip->have_interrupt(_channel);
2.28 + }
2.29 else
2.30 return true;
2.31 }
2.32 @@ -406,7 +414,12 @@
2.33 Dma_jz4780_channel::wait_for_irq(unsigned int timeout)
2.34 {
2.35 if (l4_is_valid_cap(_irq))
2.36 + {
2.37 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
2.38 + return false;
2.39 +
2.40 return !l4_error(l4_irq_receive(_irq, l4_timeout(L4_IPC_TIMEOUT_NEVER, l4util_micros2l4to(timeout)))) && _chip->have_interrupt(_channel);
2.41 + }
2.42 else
2.43 return true;
2.44 }
3.1 --- a/pkg/devices/lib/dma/src/x1600.cc Wed Feb 21 00:33:55 2024 +0100
3.2 +++ b/pkg/devices/lib/dma/src/x1600.cc Fri Feb 23 22:52:35 2024 +0100
3.3 @@ -22,11 +22,14 @@
3.4 #include <l4/devices/dma-x1600.h>
3.5 #include <l4/devices/hw_mmio_register_block.h>
3.6
3.7 -#include <l4/sys/icu.h>
3.8 #include <l4/sys/ipc.h>
3.9 #include <l4/sys/irq.h>
3.10 +#include <l4/sys/rcv_endpoint.h>
3.11 #include <l4/util/util.h>
3.12
3.13 +#include <pthread.h>
3.14 +#include <pthread-l4.h>
3.15 +
3.16 #include <stdio.h>
3.17
3.18
3.19 @@ -348,6 +351,9 @@
3.20 bool
3.21 Dma_x1600_channel::wait_for_irq()
3.22 {
3.23 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
3.24 + return false;
3.25 +
3.26 return !l4_error(l4_irq_receive(_irq, L4_IPC_NEVER)) && _chip->have_interrupt(_channel);
3.27 }
3.28
3.29 @@ -357,6 +363,9 @@
3.30 bool
3.31 Dma_x1600_channel::wait_for_irq(unsigned int timeout)
3.32 {
3.33 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
3.34 + return false;
3.35 +
3.36 return !l4_error(l4_irq_receive(_irq, l4_timeout(L4_IPC_TIMEOUT_NEVER, l4util_micros2l4to(timeout)))) && _chip->have_interrupt(_channel);
3.37 }
3.38
4.1 --- a/pkg/devices/lib/hdmi/src/jz4780.cc Wed Feb 21 00:33:55 2024 +0100
4.2 +++ b/pkg/devices/lib/hdmi/src/jz4780.cc Fri Feb 23 22:52:35 2024 +0100
4.3 @@ -51,8 +51,12 @@
4.4 #include <l4/devices/lcd-jz4740-config.h>
4.5
4.6 #include <l4/sys/irq.h>
4.7 +#include <l4/sys/rcv_endpoint.h>
4.8 #include <l4/util/util.h>
4.9
4.10 +#include <pthread.h>
4.11 +#include <pthread-l4.h>
4.12 +
4.13 /*
4.14 I2C pins:
4.15
4.16 @@ -759,6 +763,11 @@
4.17 uint8_t int_status;
4.18 l4_msgtag_t tag;
4.19
4.20 + err = l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0));
4.21 +
4.22 + if (err)
4.23 + return err;
4.24 +
4.25 do
4.26 {
4.27 tag = l4_irq_receive(_irq, L4_IPC_NEVER);
5.1 --- a/pkg/devices/lib/lcd/src/jz4740/lcd-jz4740.cc Wed Feb 21 00:33:55 2024 +0100
5.2 +++ b/pkg/devices/lib/lcd/src/jz4740/lcd-jz4740.cc Fri Feb 23 22:52:35 2024 +0100
5.3 @@ -3,7 +3,7 @@
5.4 *
5.5 * Copyright (C) Xiangfu Liu <xiangfu@sharism.cc>
5.6 * Copyright (C) 2015, 2016, 2017, 2018,
5.7 - * 2020 Paul Boddie <paul@boddie.org.uk>
5.8 + * 2020, 2024 Paul Boddie <paul@boddie.org.uk>
5.9 *
5.10 * This program is free software; you can redistribute it and/or
5.11 * modify it under the terms of the GNU General Public License as
5.12 @@ -24,9 +24,13 @@
5.13 #include <l4/devices/hw_mmio_register_block.h>
5.14 #include <l4/sys/cache.h>
5.15 #include <l4/sys/irq.h>
5.16 +#include <l4/sys/rcv_endpoint.h>
5.17 #include <l4/sys/types.h>
5.18 #include <l4/util/util.h>
5.19
5.20 +#include <pthread.h>
5.21 +#include <pthread-l4.h>
5.22 +
5.23 #include "lcd-jz4740.h"
5.24 #include "lcd-jz4740-config.h"
5.25 #include "lcd-jz4740-regs.h"
5.26 @@ -626,6 +630,11 @@
5.27
5.28 _regs[Lcd_status] = _regs[Lcd_status] & ~(_status_irq());
5.29
5.30 + long err = l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0));
5.31 +
5.32 + if (err)
5.33 + return err;
5.34 +
5.35 // Wait for a condition.
5.36
5.37 tag = l4_irq_receive(_irq, l4_timeout(L4_IPC_TIMEOUT_NEVER, l4util_micros2l4to(2000000)));
6.1 --- a/pkg/devices/lib/msc/include/msc-common.h Wed Feb 21 00:33:55 2024 +0100
6.2 +++ b/pkg/devices/lib/msc/include/msc-common.h Fri Feb 23 22:52:35 2024 +0100
6.3 @@ -130,6 +130,9 @@
6.4
6.5 uint8_t num_cards();
6.6
6.7 + uint32_t read(uint8_t card, struct dma_region *region,
6.8 + uint32_t address, uint32_t count);
6.9 +
6.10 uint32_t read_blocks(uint8_t card, struct dma_region *region,
6.11 uint32_t block_address, uint32_t block_count);
6.12 };
7.1 --- a/pkg/devices/lib/msc/include/msc-jz4780.h Wed Feb 21 00:33:55 2024 +0100
7.2 +++ b/pkg/devices/lib/msc/include/msc-jz4780.h Fri Feb 23 22:52:35 2024 +0100
7.3 @@ -97,6 +97,10 @@
7.4
7.5 void jz4780_msc_enable(void *msc_channel);
7.6
7.7 +uint32_t jz4780_msc_read(void *msc_channel, uint8_t card,
7.8 + struct dma_region *region,
7.9 + uint32_t address, uint32_t count);
7.10 +
7.11 uint32_t jz4780_msc_read_blocks(void *msc_channel, uint8_t card,
7.12 struct dma_region *region,
7.13 uint32_t block_address, uint32_t block_count);
8.1 --- a/pkg/devices/lib/msc/include/msc-x1600.h Wed Feb 21 00:33:55 2024 +0100
8.2 +++ b/pkg/devices/lib/msc/include/msc-x1600.h Fri Feb 23 22:52:35 2024 +0100
8.3 @@ -99,6 +99,10 @@
8.4
8.5 void x1600_msc_enable(void *msc_channel);
8.6
8.7 +uint32_t x1600_msc_read(void *msc_channel, uint8_t card,
8.8 + struct dma_region *region,
8.9 + uint32_t address, uint32_t count);
8.10 +
8.11 uint32_t x1600_msc_read_blocks(void *msc_channel, uint8_t card,
8.12 struct dma_region *region,
8.13 uint32_t block_address, uint32_t block_count);
9.1 --- a/pkg/devices/lib/msc/src/common.cc Wed Feb 21 00:33:55 2024 +0100
9.2 +++ b/pkg/devices/lib/msc/src/common.cc Fri Feb 23 22:52:35 2024 +0100
9.3 @@ -21,8 +21,12 @@
9.4
9.5 #include <l4/devices/hw_mmio_register_block.h>
9.6 #include <l4/sys/irq.h>
9.7 +#include <l4/sys/rcv_endpoint.h>
9.8 #include <l4/util/util.h>
9.9
9.10 +#include <pthread.h>
9.11 +#include <pthread-l4.h>
9.12 +
9.13 #include <math.h>
9.14 #include <stdio.h>
9.15
9.16 @@ -445,6 +449,9 @@
9.17 bool
9.18 Msc_channel::wait_for_irq(uint32_t flags)
9.19 {
9.20 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
9.21 + return false;
9.22 +
9.23 return !l4_error(l4_irq_receive(_irq, L4_IPC_NEVER)) &&
9.24 (_regs[Msc_interrupt_flag] & flags);
9.25 }
9.26 @@ -455,6 +462,9 @@
9.27 bool
9.28 Msc_channel::wait_for_irq(uint32_t flags, unsigned int timeout)
9.29 {
9.30 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
9.31 + return false;
9.32 +
9.33 return !l4_error(l4_irq_receive(_irq, l4_timeout(L4_IPC_TIMEOUT_NEVER,
9.34 l4util_micros2l4to(timeout)))) &&
9.35 (_regs[Msc_interrupt_flag] & flags);
9.36 @@ -798,6 +808,26 @@
9.37 return to_transfer;
9.38 }
9.39
9.40 +// Read data from the indicated card into a memory region.
9.41 +
9.42 +uint32_t
9.43 +Msc_channel::read(uint8_t card, struct dma_region *region,
9.44 + uint32_t address, uint32_t count)
9.45 +{
9.46 + uint32_t block_size = 1 << _cards[card].csd.read_blocklen;
9.47 +
9.48 + // Obtain the block address from the byte address and the number of blocks
9.49 + // from the byte count.
9.50 +
9.51 + // NOTE: Rejecting addresses and counts that are not multiples of the block
9.52 + // NOTE: size. Should produce an error.
9.53 +
9.54 + if ((address % block_size) || (count % block_size))
9.55 + return 0;
9.56 +
9.57 + return read_blocks(card, region, address / block_size, count / block_size);
9.58 +}
9.59 +
9.60 // Read blocks from the indicated card into a memory region.
9.61
9.62 uint32_t
10.1 --- a/pkg/devices/lib/msc/src/jz4780.cc Wed Feb 21 00:33:55 2024 +0100
10.2 +++ b/pkg/devices/lib/msc/src/jz4780.cc Fri Feb 23 22:52:35 2024 +0100
10.3 @@ -120,6 +120,14 @@
10.4 static_cast<Msc_channel *>(msc_channel)->enable();
10.5 }
10.6
10.7 +uint32_t jz4780_msc_read(void *msc_channel, uint8_t card,
10.8 + struct dma_region *region,
10.9 + uint32_t address, uint32_t count)
10.10 +{
10.11 + return static_cast<Msc_channel *>(msc_channel)->read(card, region,
10.12 + address, count);
10.13 +}
10.14 +
10.15 uint32_t jz4780_msc_read_blocks(void *msc_channel, uint8_t card,
10.16 struct dma_region *region,
10.17 uint32_t block_address, uint32_t block_count)
11.1 --- a/pkg/devices/lib/msc/src/x1600.cc Wed Feb 21 00:33:55 2024 +0100
11.2 +++ b/pkg/devices/lib/msc/src/x1600.cc Fri Feb 23 22:52:35 2024 +0100
11.3 @@ -137,6 +137,14 @@
11.4 static_cast<Msc_channel *>(msc_channel)->enable();
11.5 }
11.6
11.7 +uint32_t x1600_msc_read(void *msc_channel, uint8_t card,
11.8 + struct dma_region *region,
11.9 + uint32_t address, uint32_t count)
11.10 +{
11.11 + return static_cast<Msc_channel *>(msc_channel)->read(card, region,
11.12 + address, count);
11.13 +}
11.14 +
11.15 uint32_t x1600_msc_read_blocks(void *msc_channel, uint8_t card,
11.16 struct dma_region *region,
11.17 uint32_t block_address, uint32_t block_count)
12.1 --- a/pkg/devices/lib/tcu/src/common.cc Wed Feb 21 00:33:55 2024 +0100
12.2 +++ b/pkg/devices/lib/tcu/src/common.cc Fri Feb 23 22:52:35 2024 +0100
12.3 @@ -22,8 +22,12 @@
12.4 #include <l4/devices/hw_mmio_register_block.h>
12.5 #include <l4/sys/err.h>
12.6 #include <l4/sys/irq.h>
12.7 +#include <l4/sys/rcv_endpoint.h>
12.8 #include <l4/util/util.h>
12.9
12.10 +#include <pthread.h>
12.11 +#include <pthread-l4.h>
12.12 +
12.13 #include <math.h> // log2
12.14
12.15 #include "tcu-common.h"
12.16 @@ -268,7 +272,10 @@
12.17
12.18 bool
12.19 Tcu_channel::wait_for_irq()
12.20 -{
12.21 +{
12.22 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
12.23 + return false;
12.24 +
12.25 bool irq = !l4_error(l4_irq_receive(_irq, L4_IPC_NEVER)) && have_interrupt();
12.26
12.27 if (irq)
12.28 @@ -283,6 +290,9 @@
12.29 bool
12.30 Tcu_channel::wait_for_irq(unsigned int timeout)
12.31 {
12.32 + if (l4_error(l4_rcv_ep_bind_thread(_irq, pthread_l4_cap(pthread_self()), 0)))
12.33 + return false;
12.34 +
12.35 bool irq = !l4_error(l4_irq_receive(_irq, l4_timeout(L4_IPC_TIMEOUT_NEVER, l4util_micros2l4to(timeout)))) && have_interrupt();
12.36
12.37 if (irq)
13.1 --- a/pkg/landfall-examples/hw_info/hw_info.c Wed Feb 21 00:33:55 2024 +0100
13.2 +++ b/pkg/landfall-examples/hw_info/hw_info.c Fri Feb 23 22:52:35 2024 +0100
13.3 @@ -100,16 +100,6 @@
13.4 return 1;
13.5 }
13.6
13.7 - /* Attach ourselves to the interrupt handler. */
13.8 -
13.9 - err = l4_error(l4_rcv_ep_bind_thread(irq, l4re_env()->main_thread, num));
13.10 -
13.11 - if (err)
13.12 - {
13.13 - printf("Could not attach to IRQs: %ld\n", err);
13.14 - return 1;
13.15 - }
13.16 -
13.17 return 0;
13.18 }
13.19