| [5cd136ab] | 1 | /*
|
|---|
| [443695e] | 2 | * Copyright (c) 2024 Jiri Svoboda
|
|---|
| [5cd136ab] | 3 | * Copyright (c) 2010 Lenka Trochtova
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| [79ae36dd] | 29 |
|
|---|
| [54de5ebd] | 30 | /** @addtogroup libc
|
|---|
| [5cd136ab] | 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /** @file
|
|---|
| 34 | */
|
|---|
| [79ae36dd] | 35 |
|
|---|
| [4805495] | 36 | #ifndef _LIBC_DEVICE_HW_RES_H_
|
|---|
| 37 | #define _LIBC_DEVICE_HW_RES_H_
|
|---|
| [5cd136ab] | 38 |
|
|---|
| 39 | #include <ipc/dev_iface.h>
|
|---|
| [79ae36dd] | 40 | #include <async.h>
|
|---|
| [3e6a98c5] | 41 | #include <stdbool.h>
|
|---|
| [5cd136ab] | 42 |
|
|---|
| [d9cf684a] | 43 | #define DMA_MODE_ON_DEMAND 0
|
|---|
| 44 | #define DMA_MODE_WRITE (1 << 2)
|
|---|
| 45 | #define DMA_MODE_READ (1 << 3)
|
|---|
| 46 | #define DMA_MODE_AUTO (1 << 4)
|
|---|
| 47 | #define DMA_MODE_DOWN (1 << 5)
|
|---|
| 48 | #define DMA_MODE_SINGLE (1 << 6)
|
|---|
| 49 | #define DMA_MODE_BLOCK (1 << 7)
|
|---|
| 50 |
|
|---|
| [0adddea] | 51 | /** HW resource provider interface */
|
|---|
| [5dc9622] | 52 | typedef enum {
|
|---|
| [f724e82] | 53 | HW_RES_GET_RESOURCE_LIST = 0,
|
|---|
| [d9cf684a] | 54 | HW_RES_ENABLE_INTERRUPT,
|
|---|
| [d51838f] | 55 | HW_RES_DISABLE_INTERRUPT,
|
|---|
| 56 | HW_RES_CLEAR_INTERRUPT,
|
|---|
| [d9cf684a] | 57 | HW_RES_DMA_CHANNEL_SETUP,
|
|---|
| [6fd365d] | 58 | HW_RES_DMA_CHANNEL_REMAIN,
|
|---|
| [443695e] | 59 | HW_RES_GET_FLAGS
|
|---|
| [ce79069b] | 60 | } hw_res_method_t;
|
|---|
| [5dc9622] | 61 |
|
|---|
| [0adddea] | 62 | /** HW resource types */
|
|---|
| [5dc9622] | 63 | typedef enum {
|
|---|
| 64 | INTERRUPT,
|
|---|
| [79ae36dd] | 65 | IO_RANGE,
|
|---|
| [d9cf684a] | 66 | MEM_RANGE,
|
|---|
| 67 | DMA_CHANNEL_8,
|
|---|
| 68 | DMA_CHANNEL_16,
|
|---|
| [5dc9622] | 69 | } hw_res_type_t;
|
|---|
| 70 |
|
|---|
| 71 | typedef enum {
|
|---|
| 72 | LITTLE_ENDIAN = 0,
|
|---|
| 73 | BIG_ENDIAN
|
|---|
| 74 | } endianness_t;
|
|---|
| 75 |
|
|---|
| [0adddea] | 76 | /** HW resource (e.g. interrupt, memory register, i/o register etc.) */
|
|---|
| 77 | typedef struct {
|
|---|
| [3843ecb] | 78 | hw_res_type_t type;
|
|---|
| 79 | union {
|
|---|
| 80 | struct {
|
|---|
| 81 | uint64_t address;
|
|---|
| [54de5ebd] | 82 | size_t size;
|
|---|
| [9e470c0] | 83 | bool relative;
|
|---|
| 84 | endianness_t endianness;
|
|---|
| [3843ecb] | 85 | } mem_range;
|
|---|
| [a35b458] | 86 |
|
|---|
| [3843ecb] | 87 | struct {
|
|---|
| 88 | uint64_t address;
|
|---|
| [54de5ebd] | 89 | size_t size;
|
|---|
| [9e470c0] | 90 | bool relative;
|
|---|
| 91 | endianness_t endianness;
|
|---|
| [3843ecb] | 92 | } io_range;
|
|---|
| [a35b458] | 93 |
|
|---|
| [3843ecb] | 94 | struct {
|
|---|
| [54de5ebd] | 95 | int irq;
|
|---|
| 96 | } interrupt;
|
|---|
| [a35b458] | 97 |
|
|---|
| [d9cf684a] | 98 | union {
|
|---|
| 99 | unsigned int dma8;
|
|---|
| 100 | unsigned int dma16;
|
|---|
| 101 | } dma_channel;
|
|---|
| [54de5ebd] | 102 | } res;
|
|---|
| [3843ecb] | 103 | } hw_resource_t;
|
|---|
| 104 |
|
|---|
| [0adddea] | 105 | typedef struct {
|
|---|
| [3843ecb] | 106 | size_t count;
|
|---|
| [54de5ebd] | 107 | hw_resource_t *resources;
|
|---|
| [3843ecb] | 108 | } hw_resource_list_t;
|
|---|
| 109 |
|
|---|
| [f724e82] | 110 | static inline void hw_res_clean_resource_list(hw_resource_list_t *hw_res)
|
|---|
| [3843ecb] | 111 | {
|
|---|
| [0adddea] | 112 | if (hw_res->resources != NULL) {
|
|---|
| [3843ecb] | 113 | free(hw_res->resources);
|
|---|
| 114 | hw_res->resources = NULL;
|
|---|
| 115 | }
|
|---|
| [a35b458] | 116 |
|
|---|
| [54de5ebd] | 117 | hw_res->count = 0;
|
|---|
| 118 | }
|
|---|
| [5dc9622] | 119 |
|
|---|
| [443695e] | 120 | typedef enum {
|
|---|
| 121 | /** This is an PCI/ISA bridge, not 'classic' ISA bus */
|
|---|
| 122 | hwf_isa_bridge = 0x1
|
|---|
| 123 | } hw_res_flags_t;
|
|---|
| 124 |
|
|---|
| [b7fd2a0] | 125 | extern errno_t hw_res_get_resource_list(async_sess_t *, hw_resource_list_t *);
|
|---|
| 126 | extern errno_t hw_res_enable_interrupt(async_sess_t *, int);
|
|---|
| 127 | extern errno_t hw_res_disable_interrupt(async_sess_t *, int);
|
|---|
| 128 | extern errno_t hw_res_clear_interrupt(async_sess_t *, int);
|
|---|
| [5cd136ab] | 129 |
|
|---|
| [b7fd2a0] | 130 | extern errno_t hw_res_dma_channel_setup(async_sess_t *, unsigned int, uint32_t,
|
|---|
| [301032a] | 131 | uint32_t, uint8_t);
|
|---|
| [b7fd2a0] | 132 | extern errno_t hw_res_dma_channel_remain(async_sess_t *, unsigned, size_t *);
|
|---|
| [443695e] | 133 | extern errno_t hw_res_get_flags(async_sess_t *, hw_res_flags_t *);
|
|---|
| [d9cf684a] | 134 |
|
|---|
| [5cd136ab] | 135 | #endif
|
|---|
| 136 |
|
|---|
| 137 | /** @}
|
|---|
| [be942bc] | 138 | */
|
|---|