[5cd136ab] | 1 | /*
|
---|
[832cbe7] | 2 | * Copyright (c) 2025 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,
|
---|
[832cbe7] | 59 | HW_RES_QUERY_LEGACY_IO,
|
---|
| 60 | HW_RES_CLAIM_LEGACY_IO
|
---|
[ce79069b] | 61 | } hw_res_method_t;
|
---|
[5dc9622] | 62 |
|
---|
[0adddea] | 63 | /** HW resource types */
|
---|
[5dc9622] | 64 | typedef enum {
|
---|
| 65 | INTERRUPT,
|
---|
[79ae36dd] | 66 | IO_RANGE,
|
---|
[d9cf684a] | 67 | MEM_RANGE,
|
---|
| 68 | DMA_CHANNEL_8,
|
---|
| 69 | DMA_CHANNEL_16,
|
---|
[5dc9622] | 70 | } hw_res_type_t;
|
---|
| 71 |
|
---|
| 72 | typedef enum {
|
---|
| 73 | LITTLE_ENDIAN = 0,
|
---|
| 74 | BIG_ENDIAN
|
---|
| 75 | } endianness_t;
|
---|
| 76 |
|
---|
[0adddea] | 77 | /** HW resource (e.g. interrupt, memory register, i/o register etc.) */
|
---|
| 78 | typedef struct {
|
---|
[3843ecb] | 79 | hw_res_type_t type;
|
---|
| 80 | union {
|
---|
| 81 | struct {
|
---|
| 82 | uint64_t address;
|
---|
[54de5ebd] | 83 | size_t size;
|
---|
[9e470c0] | 84 | bool relative;
|
---|
| 85 | endianness_t endianness;
|
---|
[3843ecb] | 86 | } mem_range;
|
---|
[a35b458] | 87 |
|
---|
[3843ecb] | 88 | struct {
|
---|
| 89 | uint64_t address;
|
---|
[54de5ebd] | 90 | size_t size;
|
---|
[9e470c0] | 91 | bool relative;
|
---|
| 92 | endianness_t endianness;
|
---|
[3843ecb] | 93 | } io_range;
|
---|
[a35b458] | 94 |
|
---|
[3843ecb] | 95 | struct {
|
---|
[54de5ebd] | 96 | int irq;
|
---|
| 97 | } interrupt;
|
---|
[a35b458] | 98 |
|
---|
[d9cf684a] | 99 | union {
|
---|
| 100 | unsigned int dma8;
|
---|
| 101 | unsigned int dma16;
|
---|
| 102 | } dma_channel;
|
---|
[54de5ebd] | 103 | } res;
|
---|
[3843ecb] | 104 | } hw_resource_t;
|
---|
| 105 |
|
---|
[0adddea] | 106 | typedef struct {
|
---|
[3843ecb] | 107 | size_t count;
|
---|
[54de5ebd] | 108 | hw_resource_t *resources;
|
---|
[3843ecb] | 109 | } hw_resource_list_t;
|
---|
| 110 |
|
---|
[f724e82] | 111 | static inline void hw_res_clean_resource_list(hw_resource_list_t *hw_res)
|
---|
[3843ecb] | 112 | {
|
---|
[0adddea] | 113 | if (hw_res->resources != NULL) {
|
---|
[3843ecb] | 114 | free(hw_res->resources);
|
---|
| 115 | hw_res->resources = NULL;
|
---|
| 116 | }
|
---|
[a35b458] | 117 |
|
---|
[54de5ebd] | 118 | hw_res->count = 0;
|
---|
| 119 | }
|
---|
[5dc9622] | 120 |
|
---|
[832cbe7] | 121 | /** Claims to legacy devices */
|
---|
[443695e] | 122 | typedef enum {
|
---|
[832cbe7] | 123 | /** 'Legacy' ISA IDE I/O ranges */
|
---|
| 124 | hwc_isa_ide = 0x1
|
---|
| 125 | } hw_res_claims_t;
|
---|
[443695e] | 126 |
|
---|
[b7fd2a0] | 127 | extern errno_t hw_res_get_resource_list(async_sess_t *, hw_resource_list_t *);
|
---|
| 128 | extern errno_t hw_res_enable_interrupt(async_sess_t *, int);
|
---|
| 129 | extern errno_t hw_res_disable_interrupt(async_sess_t *, int);
|
---|
| 130 | extern errno_t hw_res_clear_interrupt(async_sess_t *, int);
|
---|
[5cd136ab] | 131 |
|
---|
[b7fd2a0] | 132 | extern errno_t hw_res_dma_channel_setup(async_sess_t *, unsigned int, uint32_t,
|
---|
[301032a] | 133 | uint32_t, uint8_t);
|
---|
[b7fd2a0] | 134 | extern errno_t hw_res_dma_channel_remain(async_sess_t *, unsigned, size_t *);
|
---|
[832cbe7] | 135 | extern errno_t hw_res_query_legacy_io(async_sess_t *, hw_res_claims_t *);
|
---|
| 136 | extern errno_t hw_res_claim_legacy_io(async_sess_t *, hw_res_claims_t);
|
---|
[d9cf684a] | 137 |
|
---|
[5cd136ab] | 138 | #endif
|
---|
| 139 |
|
---|
| 140 | /** @}
|
---|
[be942bc] | 141 | */
|
---|