[00d7e1b] | 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 |
|
---|
[4805495] | 35 | #ifndef _LIBC_DEVICE_HW_RES_PARSED_H_
|
---|
| 36 | #define _LIBC_DEVICE_HW_RES_PARSED_H_
|
---|
[00d7e1b] | 37 |
|
---|
| 38 | #include <device/hw_res.h>
|
---|
[8049b79] | 39 | #include <device/pio_window.h>
|
---|
[00d7e1b] | 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 |
|
---|
[8049b79] | 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 |
|
---|
| 54 | typedef struct address64 {
|
---|
[1b20da0] | 55 | /** Aboslute address. */
|
---|
[8049b79] | 56 | uint64_t absolute;
|
---|
| 57 | /** PIO window base relative address. */
|
---|
[1b20da0] | 58 | uint64_t relative;
|
---|
[8049b79] | 59 | } address64_t;
|
---|
| 60 |
|
---|
[00d7e1b] | 61 | /** Address range structure */
|
---|
| 62 | typedef struct addr_range {
|
---|
| 63 | /** Start address */
|
---|
[8049b79] | 64 | address64_t address;
|
---|
[a35b458] | 65 |
|
---|
[00d7e1b] | 66 | /** Area size */
|
---|
| 67 | size_t size;
|
---|
[8049b79] | 68 |
|
---|
| 69 | /** Endianness */
|
---|
| 70 | endianness_t endianness;
|
---|
[00d7e1b] | 71 | } addr_range_t;
|
---|
| 72 |
|
---|
| 73 | /** IO range type */
|
---|
| 74 | typedef addr_range_t io_range_t;
|
---|
| 75 |
|
---|
| 76 | /** Memory range type */
|
---|
| 77 | typedef addr_range_t mem_range_t;
|
---|
| 78 |
|
---|
| 79 | /** List of IRQs */
|
---|
| 80 | typedef struct irq_list {
|
---|
| 81 | /** Irq count */
|
---|
| 82 | size_t count;
|
---|
[a35b458] | 83 |
|
---|
[00d7e1b] | 84 | /** Array of IRQs */
|
---|
| 85 | int *irqs;
|
---|
| 86 | } irq_list_t;
|
---|
| 87 |
|
---|
[46d9d13] | 88 | /** List of ISA DMA channels */
|
---|
| 89 | typedef struct dma_list {
|
---|
| 90 | /** Channel count */
|
---|
| 91 | size_t count;
|
---|
| 92 |
|
---|
| 93 | /** Array of channels */
|
---|
[d9cf684a] | 94 | unsigned int *channels;
|
---|
[46d9d13] | 95 | } dma_list_t;
|
---|
| 96 |
|
---|
[00d7e1b] | 97 | /** List of memory areas */
|
---|
| 98 | typedef struct addr_range_list {
|
---|
| 99 | /** Areas count */
|
---|
| 100 | size_t count;
|
---|
[a35b458] | 101 |
|
---|
[00d7e1b] | 102 | /** Array of areas */
|
---|
| 103 | addr_range_t *ranges;
|
---|
| 104 | } addr_range_list_t;
|
---|
| 105 |
|
---|
| 106 | /** List of IO mapped areas */
|
---|
| 107 | typedef addr_range_list_t io_range_list_t;
|
---|
| 108 |
|
---|
| 109 | /** Memory range type */
|
---|
| 110 | typedef addr_range_list_t mem_range_list_t;
|
---|
| 111 |
|
---|
| 112 | /** HW resources parsed according to resource type */
|
---|
| 113 | typedef struct hw_resource_list_parsed {
|
---|
| 114 | /** List of IRQs */
|
---|
| 115 | irq_list_t irqs;
|
---|
[a35b458] | 116 |
|
---|
[d9cf684a] | 117 | /** List of DMA channels */
|
---|
| 118 | dma_list_t dma_channels;
|
---|
[a35b458] | 119 |
|
---|
[00d7e1b] | 120 | /** List of memory areas */
|
---|
| 121 | mem_range_list_t mem_ranges;
|
---|
[a35b458] | 122 |
|
---|
[00d7e1b] | 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 | */
|
---|
| 133 | static inline void hw_res_list_parsed_clean(hw_res_list_parsed_t *list)
|
---|
| 134 | {
|
---|
| 135 | if (list == NULL)
|
---|
| 136 | return;
|
---|
[a35b458] | 137 |
|
---|
[00d7e1b] | 138 | free(list->irqs.irqs);
|
---|
| 139 | free(list->io_ranges.ranges);
|
---|
| 140 | free(list->mem_ranges.ranges);
|
---|
[46d9d13] | 141 | free(list->dma_channels.channels);
|
---|
[a35b458] | 142 |
|
---|
[acdb5bac] | 143 | memset(list, 0, sizeof(hw_res_list_parsed_t));
|
---|
[00d7e1b] | 144 | }
|
---|
| 145 |
|
---|
| 146 | /** Initialize the hw_resource_list_parsed_t structure
|
---|
| 147 | *
|
---|
| 148 | * @param list The structure to initialize
|
---|
| 149 | */
|
---|
| 150 | static inline void hw_res_list_parsed_init(hw_res_list_parsed_t *list)
|
---|
| 151 | {
|
---|
[acdb5bac] | 152 | memset(list, 0, sizeof(hw_res_list_parsed_t));
|
---|
[00d7e1b] | 153 | }
|
---|
| 154 |
|
---|
[b7fd2a0] | 155 | extern errno_t hw_res_list_parse(const pio_window_t *, const hw_resource_list_t *,
|
---|
[cf02eaf] | 156 | hw_res_list_parsed_t *, int);
|
---|
[b7fd2a0] | 157 | extern errno_t hw_res_get_list_parsed(async_sess_t *, hw_res_list_parsed_t *, int);
|
---|
[00d7e1b] | 158 |
|
---|
| 159 | #endif
|
---|
| 160 |
|
---|
| 161 | /** @}
|
---|
| 162 | */
|
---|