1.1 --- a/pkg/landfall-examples/hw_info/hw_info.c Sun Feb 11 00:36:08 2024 +0100
1.2 +++ b/pkg/landfall-examples/hw_info/hw_info.c Sun Feb 11 00:39:56 2024 +0100
1.3 @@ -1112,6 +1112,92 @@
1.4
1.5
1.6
1.7 +/* MSC configuration. */
1.8 +
1.9 +static l4_uint32_t msc_irq_start = 0, msc_irq_end = 0;
1.10 +
1.11 +/* MSC operations. */
1.12 +
1.13 +static void list_msc_channels(void)
1.14 +{
1.15 + unsigned int num;
1.16 + void *channel;
1.17 +
1.18 + printf("Channel Status\n");
1.19 + printf("------- --------\n");
1.20 +
1.21 + for (num = 0; num < num_msc_channels; num++)
1.22 + {
1.23 + printf("%d ", num);
1.24 +
1.25 + channel = msc_channels[num];
1.26 +
1.27 + if (channel == NULL)
1.28 + printf("inactive\n");
1.29 + else
1.30 + printf("%08x\n", msc_get_status(channel));
1.31 + }
1.32 +}
1.33 +
1.34 +static void new_msc_channel(void *msc)
1.35 +{
1.36 + l4_cap_idx_t irqcap;
1.37 + int num = get_channel_number(num_msc_channels);
1.38 + void *channel;
1.39 +
1.40 + if (num < 0)
1.41 + return;
1.42 +
1.43 + channel = get_channel(num_dma_channels, dma_channels, NULL);
1.44 +
1.45 + if (channel == NULL)
1.46 + return;
1.47 +
1.48 + irqcap = l4re_util_cap_alloc();
1.49 +
1.50 + if (init_irq(num, irqcap, msc_irq_start, msc_irq_end))
1.51 + return;
1.52 +
1.53 + msc_channels[num] = msc_get_channel(msc, num, irqcap, channel);
1.54 + msc_irqs[num] = irqcap;
1.55 +}
1.56 +
1.57 +static void enable_msc_channel(void)
1.58 +{
1.59 + void *channel = get_channel(num_msc_channels, msc_channels, NULL);
1.60 +
1.61 + if (channel == NULL)
1.62 + return;
1.63 +
1.64 + msc_enable(channel);
1.65 +}
1.66 +
1.67 +static void read_block_from_msc(void)
1.68 +{
1.69 + void *channel = get_channel(num_msc_channels, msc_channels, NULL);
1.70 + struct dma_region *dma_region = NULL;
1.71 + uint32_t card, transferred;
1.72 +
1.73 + if (channel == NULL)
1.74 + return;
1.75 +
1.76 + dma_region = _get_dma_region();
1.77 +
1.78 + if (dma_region == NULL)
1.79 + return;
1.80 +
1.81 + if (!read_number("Card", &card))
1.82 + return;
1.83 +
1.84 + l4_cache_inv_data(dma_region->vaddr, dma_region->vaddr + dma_region->size);
1.85 +
1.86 + transferred = msc_read_block(channel, (uint8_t) card, dma_region->paddr);
1.87 +
1.88 + printf("Transferred: %d\n", transferred);
1.89 +}
1.90 +
1.91 +
1.92 +
1.93 /* RTC operations. */
1.94
1.95 static void rtc_reset(void *rtc, void *cpm)
1.96 @@ -1375,6 +1461,7 @@
1.97
1.98 printf(" Clock.. Counter......... Mask..............\n");
1.99 printf("Channel Status C Pre Cnt Half Full Half Full Int\n");
1.100 + printf("------- -------- -- ---- ---- ---- ---- -------- -------- ----\n");
1.101
1.102 for (num = 0; num < num_tcu_channels; num++)
1.103 {
1.104 @@ -1625,6 +1712,27 @@
1.105 list_memory_regions();
1.106 }
1.107
1.108 +static void handle_msc(void *msc)
1.109 +{
1.110 + char *token;
1.111 +
1.112 + if ((token = read_token(NULL)) != NULL)
1.113 + {
1.114 + if (!strcmp(token, "l") || !strcmp(token, "list"))
1.115 + list_msc_channels();
1.116 + else if (!strcmp(token, "c") || !strcmp(token, "channel"))
1.117 + new_msc_channel(msc);
1.118 + else if (!strcmp(token, "e") || !strcmp(token, "enable"))
1.119 + enable_msc_channel();
1.120 + else if (!strcmp(token, "r") || !strcmp(token, "read"))
1.121 + read_block_from_msc();
1.122 + else
1.123 + printf("msc channel | enable | read\n");
1.124 + }
1.125 + else
1.126 + list_msc_channels();
1.127 +}
1.128 +
1.129 static void handle_rtc(void *rtc, void *cpm)
1.130 {
1.131 char *token;
1.132 @@ -1736,11 +1844,13 @@
1.133 l4_addr_t dma_base = 0, dma_base_end = 0;
1.134 l4_addr_t gpio_base = 0, gpio_base_end = 0;
1.135 l4_addr_t i2c_base = 0, i2c_base_end = 0;
1.136 + l4_addr_t msc_base = 0, msc_base_end = 0;
1.137 + l4_addr_t msc_phys_base = 0, msc_phys_base_end = 0;
1.138 l4_addr_t rtc_base = 0, rtc_base_end = 0;
1.139 l4_addr_t ssi_base = 0, ssi_base_end = 0;
1.140 l4_addr_t ssi_phys_base = 0, ssi_phys_base_end = 0;
1.141 l4_addr_t tcu_base = 0, tcu_base_end = 0;
1.142 - void *aic, *cpm, *dma, *gpio[num_gpio_ports], *i2c, *rtc, *spi, *tcu;
1.143 + void *aic, *cpm, *dma, *gpio[num_gpio_ports], *i2c, *msc, *rtc, *spi, *tcu;
1.144 int result = 0;
1.145 unsigned int port;
1.146
1.147 @@ -1811,6 +1921,21 @@
1.148
1.149 aic = aic_init(aic_phys_base, aic_base, aic_base_end, cpm);
1.150
1.151 + printf("Access MSC...\n");
1.152 +
1.153 + if ((result = get_memory_complete(io_memory_regions[MSC], &msc_base, &msc_base_end,
1.154 + &msc_phys_base, &msc_phys_base_end)) < 0)
1.155 + return 1;
1.156 +
1.157 + printf("MSC at 0x%lx...0x%lx.\n", msc_base, msc_base_end);
1.158 +
1.159 + msc = msc_init(msc_phys_base, msc_base, msc_base_end);
1.160 +
1.161 + if (get_irq(io_memory_regions[MSC], &msc_irq_start, &msc_irq_end) < 0)
1.162 + return 1;
1.163 +
1.164 + printf("IRQ range at %d...%d.\n", msc_irq_start, msc_irq_end);
1.165 +
1.166 printf("Access RTC...\n");
1.167
1.168 if ((result = get_memory(io_memory_regions[RTC], &rtc_base, &rtc_base_end)) < 0)
1.169 @@ -1849,7 +1974,7 @@
1.170
1.171 /* Start the interactive session. */
1.172
1.173 - printf("aic, cpm, dma, gpio, i2c, rtc, spi, tcu\n");
1.174 + printf("aic, cpm, dma, gpio, i2c, msc, rtc, spi, tcu\n");
1.175
1.176 while (1)
1.177 {
1.178 @@ -1890,6 +2015,11 @@
1.179 else if (!strcmp(token, "i") || !strcmp(token, "i2c"))
1.180 handle_i2c(i2c);
1.181
1.182 + /* MSC commands. */
1.183 +
1.184 + else if (!strcmp(token, "M") || !strcmp(token, "msc"))
1.185 + handle_msc(msc);
1.186 +
1.187 /* Generic memory commands. */
1.188
1.189 else if (!strcmp(token, "m") || !strcmp(token, "mem") || !strcmp(token, "memory"))