|
| 1 | +/* |
| 2 | + * Copyright (c) 2018 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr.h> |
| 8 | +#include <ipm.h> |
| 9 | + |
| 10 | +#include <openamp/open_amp.h> |
| 11 | +#include "platform.h" |
| 12 | + |
| 13 | +static K_SEM_DEFINE(data_sem, 0, 1); |
| 14 | +static struct device *ipm_handle; |
| 15 | + |
| 16 | +static void platform_ipm_callback(void *context, u32_t id, volatile void *data) |
| 17 | +{ |
| 18 | + k_sem_give(&data_sem); |
| 19 | +} |
| 20 | + |
| 21 | +static int enable_interrupt(struct proc_intr *intr) |
| 22 | +{ |
| 23 | + return ipm_set_enabled(ipm_handle, 1); |
| 24 | +} |
| 25 | + |
| 26 | +static void notify(struct hil_proc *proc, struct proc_intr *intr_info) |
| 27 | +{ |
| 28 | + u32_t dummy_data = 0x12345678; /* Some data must be provided */ |
| 29 | + |
| 30 | + ipm_send(ipm_handle, 0, 0, &dummy_data, sizeof(dummy_data)); |
| 31 | +} |
| 32 | + |
| 33 | +static int boot_cpu(struct hil_proc *proc, unsigned int load_addr) |
| 34 | +{ |
| 35 | + return -1; |
| 36 | +} |
| 37 | + |
| 38 | +static void shutdown_cpu(struct hil_proc *proc) |
| 39 | +{ |
| 40 | +} |
| 41 | + |
| 42 | +static int poll(struct hil_proc *proc, int nonblock) |
| 43 | +{ |
| 44 | + int status = k_sem_take(&data_sem, nonblock ? K_NO_WAIT : K_FOREVER); |
| 45 | + |
| 46 | + if (status == 0) { |
| 47 | + hil_notified(proc, 0xffffffff); |
| 48 | + } |
| 49 | + |
| 50 | + return status; |
| 51 | +} |
| 52 | + |
| 53 | +static struct metal_io_region *alloc_shm(struct hil_proc *proc, |
| 54 | + metal_phys_addr_t physical, |
| 55 | + size_t size, |
| 56 | + struct metal_device **device) |
| 57 | +{ |
| 58 | + int status = metal_device_open("generic", SHM_DEVICE_NAME, device); |
| 59 | + |
| 60 | + if (status != 0) { |
| 61 | + return NULL; |
| 62 | + } |
| 63 | + |
| 64 | + return metal_device_io_region(*device, 0); |
| 65 | +} |
| 66 | + |
| 67 | +static void release_shm(struct hil_proc *proc, struct metal_device *device, |
| 68 | + struct metal_io_region *io) |
| 69 | +{ |
| 70 | + metal_device_close(device); |
| 71 | +} |
| 72 | + |
| 73 | +static int initialize(struct hil_proc *proc) |
| 74 | +{ |
| 75 | + ipm_handle = device_get_binding("MAILBOX_0"); |
| 76 | + if (!ipm_handle) { |
| 77 | + return -1; |
| 78 | + } |
| 79 | + |
| 80 | + ipm_register_callback(ipm_handle, platform_ipm_callback, NULL); |
| 81 | + return 0; |
| 82 | +} |
| 83 | + |
| 84 | +static void release(struct hil_proc *proc) |
| 85 | +{ |
| 86 | + ipm_set_enabled(ipm_handle, 0); |
| 87 | +} |
| 88 | + |
| 89 | +struct hil_platform_ops platform_ops = { |
| 90 | + .enable_interrupt = enable_interrupt, |
| 91 | + .notify = notify, |
| 92 | + .boot_cpu = boot_cpu, |
| 93 | + .shutdown_cpu = shutdown_cpu, |
| 94 | + .poll = poll, |
| 95 | + .alloc_shm = alloc_shm, |
| 96 | + .release_shm = release_shm, |
| 97 | + .initialize = initialize, |
| 98 | + .release = release |
| 99 | +}; |
| 100 | + |
0 commit comments