source: mainline/uspace/lib/c/include/device/hw_res_parsed.h

Last change on this file was 4805495, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Make sure libc and abi header guards are reserved identifiers

It's only needed for a small subset that end up included from standard
headers, but for consistency this changes all of them.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Michalec
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#ifndef _LIBC_DEVICE_HW_RES_PARSED_H_
36#define _LIBC_DEVICE_HW_RES_PARSED_H_
37
38#include <device/hw_res.h>
39#include <device/pio_window.h>
40#include <str.h>
41
42/** Keep areas of the zero size in the list */
43#define HW_RES_KEEP_ZERO_AREA 0x1
44
45/** Keep duplicit entries */
46#define HW_RES_KEEP_DUPLICIT 0x2
47
48#define RNGABS(rng) (rng).address.absolute
49#define RNGREL(rng) (rng).address.relative
50#define RNGSZ(rng) (rng).size
51
52#define RNGABSPTR(rng) ((void *) ((uintptr_t) RNGABS((rng))))
53
54typedef struct address64 {
55 /** Aboslute address. */
56 uint64_t absolute;
57 /** PIO window base relative address. */
58 uint64_t relative;
59} address64_t;
60
61/** Address range structure */
62typedef struct addr_range {
63 /** Start address */
64 address64_t address;
65
66 /** Area size */
67 size_t size;
68
69 /** Endianness */
70 endianness_t endianness;
71} addr_range_t;
72
73/** IO range type */
74typedef addr_range_t io_range_t;
75
76/** Memory range type */
77typedef addr_range_t mem_range_t;
78
79/** List of IRQs */
80typedef struct irq_list {
81 /** Irq count */
82 size_t count;
83
84 /** Array of IRQs */
85 int *irqs;
86} irq_list_t;
87
88/** List of ISA DMA channels */
89typedef struct dma_list {
90 /** Channel count */
91 size_t count;
92
93 /** Array of channels */
94 unsigned int *channels;
95} dma_list_t;
96
97/** List of memory areas */
98typedef struct addr_range_list {
99 /** Areas count */
100 size_t count;
101
102 /** Array of areas */
103 addr_range_t *ranges;
104} addr_range_list_t;
105
106/** List of IO mapped areas */
107typedef addr_range_list_t io_range_list_t;
108
109/** Memory range type */
110typedef addr_range_list_t mem_range_list_t;
111
112/** HW resources parsed according to resource type */
113typedef struct hw_resource_list_parsed {
114 /** List of IRQs */
115 irq_list_t irqs;
116
117 /** List of DMA channels */
118 dma_list_t dma_channels;
119
120 /** List of memory areas */
121 mem_range_list_t mem_ranges;
122
123 /** List of IO areas */
124 io_range_list_t io_ranges;
125} hw_res_list_parsed_t;
126
127/** Clean hw_resource_list_parsed_t structure
128 *
129 * All allocated memory will be released, data amd pointers set to 0.
130 *
131 * @param list The structure to clear
132 */
133static inline void hw_res_list_parsed_clean(hw_res_list_parsed_t *list)
134{
135 if (list == NULL)
136 return;
137
138 free(list->irqs.irqs);
139 free(list->io_ranges.ranges);
140 free(list->mem_ranges.ranges);
141 free(list->dma_channels.channels);
142
143 memset(list, 0, sizeof(hw_res_list_parsed_t));
144}
145
146/** Initialize the hw_resource_list_parsed_t structure
147 *
148 * @param list The structure to initialize
149 */
150static inline void hw_res_list_parsed_init(hw_res_list_parsed_t *list)
151{
152 memset(list, 0, sizeof(hw_res_list_parsed_t));
153}
154
155extern errno_t hw_res_list_parse(const pio_window_t *, const hw_resource_list_t *,
156 hw_res_list_parsed_t *, int);
157extern errno_t hw_res_get_list_parsed(async_sess_t *, hw_res_list_parsed_t *, int);
158
159#endif
160
161/** @}
162 */
Note: See TracBrowser for help on using the repository browser.