1 | /*
|
---|
2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
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 | */
|
---|
29 |
|
---|
30 | /** @addtogroup libc
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /** @file
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef _LIBC_DEVICE_HW_RES_H_
|
---|
37 | #define _LIBC_DEVICE_HW_RES_H_
|
---|
38 |
|
---|
39 | #include <ipc/dev_iface.h>
|
---|
40 | #include <async.h>
|
---|
41 | #include <stdbool.h>
|
---|
42 |
|
---|
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 |
|
---|
51 | /** HW resource provider interface */
|
---|
52 | typedef enum {
|
---|
53 | HW_RES_GET_RESOURCE_LIST = 0,
|
---|
54 | HW_RES_ENABLE_INTERRUPT,
|
---|
55 | HW_RES_DISABLE_INTERRUPT,
|
---|
56 | HW_RES_CLEAR_INTERRUPT,
|
---|
57 | HW_RES_DMA_CHANNEL_SETUP,
|
---|
58 | HW_RES_DMA_CHANNEL_REMAIN,
|
---|
59 | HW_RES_QUERY_LEGACY_IO,
|
---|
60 | HW_RES_CLAIM_LEGACY_IO
|
---|
61 | } hw_res_method_t;
|
---|
62 |
|
---|
63 | /** HW resource types */
|
---|
64 | typedef enum {
|
---|
65 | INTERRUPT,
|
---|
66 | IO_RANGE,
|
---|
67 | MEM_RANGE,
|
---|
68 | DMA_CHANNEL_8,
|
---|
69 | DMA_CHANNEL_16,
|
---|
70 | } hw_res_type_t;
|
---|
71 |
|
---|
72 | typedef enum {
|
---|
73 | LITTLE_ENDIAN = 0,
|
---|
74 | BIG_ENDIAN
|
---|
75 | } endianness_t;
|
---|
76 |
|
---|
77 | /** HW resource (e.g. interrupt, memory register, i/o register etc.) */
|
---|
78 | typedef struct {
|
---|
79 | hw_res_type_t type;
|
---|
80 | union {
|
---|
81 | struct {
|
---|
82 | uint64_t address;
|
---|
83 | size_t size;
|
---|
84 | bool relative;
|
---|
85 | endianness_t endianness;
|
---|
86 | } mem_range;
|
---|
87 |
|
---|
88 | struct {
|
---|
89 | uint64_t address;
|
---|
90 | size_t size;
|
---|
91 | bool relative;
|
---|
92 | endianness_t endianness;
|
---|
93 | } io_range;
|
---|
94 |
|
---|
95 | struct {
|
---|
96 | int irq;
|
---|
97 | } interrupt;
|
---|
98 |
|
---|
99 | union {
|
---|
100 | unsigned int dma8;
|
---|
101 | unsigned int dma16;
|
---|
102 | } dma_channel;
|
---|
103 | } res;
|
---|
104 | } hw_resource_t;
|
---|
105 |
|
---|
106 | typedef struct {
|
---|
107 | size_t count;
|
---|
108 | hw_resource_t *resources;
|
---|
109 | } hw_resource_list_t;
|
---|
110 |
|
---|
111 | static inline void hw_res_clean_resource_list(hw_resource_list_t *hw_res)
|
---|
112 | {
|
---|
113 | if (hw_res->resources != NULL) {
|
---|
114 | free(hw_res->resources);
|
---|
115 | hw_res->resources = NULL;
|
---|
116 | }
|
---|
117 |
|
---|
118 | hw_res->count = 0;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /** Claims to legacy devices */
|
---|
122 | typedef enum {
|
---|
123 | /** 'Legacy' ISA IDE I/O ranges */
|
---|
124 | hwc_isa_ide = 0x1
|
---|
125 | } hw_res_claims_t;
|
---|
126 |
|
---|
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);
|
---|
131 |
|
---|
132 | extern errno_t hw_res_dma_channel_setup(async_sess_t *, unsigned int, uint32_t,
|
---|
133 | uint32_t, uint8_t);
|
---|
134 | extern errno_t hw_res_dma_channel_remain(async_sess_t *, unsigned, size_t *);
|
---|
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);
|
---|
137 |
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | /** @}
|
---|
141 | */
|
---|