1/* 2 * Copyright 2019, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9/*** 10 * @module device.h 11 * The device.h interface provides a series of datastructures and helpers to manage VMM devices. 12 */ 13 14#include <stdint.h> 15#include <sel4vm/guest_vm.h> 16 17/*** 18 * @struct device 19 * Device Management Object 20 * @param {const char *} name A string representation of the device. Useful for debugging 21 * @param {seL4_Word} pstart The physical address of the device 22 * @param {seL4_Word} size Device mapping size 23 * @param {int *(vm_t, vm_vcpu_t, dev, addr, len)} handle_device_fault Fault handler 24 * @param {void *} priv Device emulation private data 25 * 26 */ 27struct device { 28 const char *name; 29 seL4_Word pstart; 30 seL4_Word size; 31 int (*handle_device_fault)(vm_t *vm, vm_vcpu_t *vcpu, struct device *dev, uintptr_t addr, size_t len); 32 void *priv; 33}; 34 35/*** 36 * @struct device_list 37 * Management for a list of devices 38 * @param {struct device *} devices List of registered devices 39 * @param {int} num_devices Total number of registered devices 40 */ 41typedef struct device_list { 42 struct device *devices; 43 int num_devices; 44} device_list_t; 45 46/*** 47 * @function device_list_init(list) 48 * Initialise an empty device list 49 * @param {device_list_t *} list device list to initialise 50 * @return 0 on success, otherwise -1 for error 51 */ 52int device_list_init(device_list_t *list); 53 54/*** 55 * @function add_device(dev_list, d) 56 * Add a generic device to a given device list without performing any initialisation of the device 57 * @param {device_list_t *} dev_list A handle to the device list that the device should be installed into 58 * @param {const struct device *} device A description of the device 59 * @return 0 on success, otherwise -1 for error 60 */ 61int add_device(device_list_t *dev_list, const struct device *d); 62 63/*** 64 * @function find_device_by_pa(dev_list, addr) 65 * Find a device by a given addr within a device list 66 * @param {device_list_t *} dev_list Device list to search within 67 * @param {uintptr_t} addr Add to search with 68 * @return Pointer to device if found, otherwise NULL if not found 69 */ 70struct device *find_device_by_pa(device_list_t *dev_list, uintptr_t addr); 71