| 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 <str.h>
|
|---|
| 40 |
|
|---|
| 41 | /** Keep areas of the zero size in the list */
|
|---|
| 42 | #define HW_RES_KEEP_ZERO_AREA 0x1
|
|---|
| 43 |
|
|---|
| 44 | /** Keep duplicit entries */
|
|---|
| 45 | #define HW_RES_KEEP_DUPLICIT 0x2
|
|---|
| 46 |
|
|---|
| 47 | /** Address range structure */
|
|---|
| 48 | typedef struct addr_range {
|
|---|
| 49 | /** Start address */
|
|---|
| 50 | uint64_t address;
|
|---|
| 51 |
|
|---|
| 52 | /** Endianness */
|
|---|
| 53 | endianness_t endianness;
|
|---|
| 54 |
|
|---|
| 55 | /** Area size */
|
|---|
| 56 | size_t size;
|
|---|
| 57 | } addr_range_t;
|
|---|
| 58 |
|
|---|
| 59 | /** IO range type */
|
|---|
| 60 | typedef addr_range_t io_range_t;
|
|---|
| 61 |
|
|---|
| 62 | /** Memory range type */
|
|---|
| 63 | typedef addr_range_t mem_range_t;
|
|---|
| 64 |
|
|---|
| 65 | /** List of IRQs */
|
|---|
| 66 | typedef struct irq_list {
|
|---|
| 67 | /** Irq count */
|
|---|
| 68 | size_t count;
|
|---|
| 69 |
|
|---|
| 70 | /** Array of IRQs */
|
|---|
| 71 | int *irqs;
|
|---|
| 72 | } irq_list_t;
|
|---|
| 73 |
|
|---|
| 74 | /** List of ISA DMA channels */
|
|---|
| 75 | typedef struct dma_list {
|
|---|
| 76 | /** Channel count */
|
|---|
| 77 | size_t count;
|
|---|
| 78 |
|
|---|
| 79 | /** Array of channels */
|
|---|
| 80 | unsigned int *channels;
|
|---|
| 81 | } dma_list_t;
|
|---|
| 82 |
|
|---|
| 83 | /** List of memory areas */
|
|---|
| 84 | typedef struct addr_range_list {
|
|---|
| 85 | /** Areas count */
|
|---|
| 86 | size_t count;
|
|---|
| 87 |
|
|---|
| 88 | /** Array of areas */
|
|---|
| 89 | addr_range_t *ranges;
|
|---|
| 90 | } addr_range_list_t;
|
|---|
| 91 |
|
|---|
| 92 | /** List of IO mapped areas */
|
|---|
| 93 | typedef addr_range_list_t io_range_list_t;
|
|---|
| 94 |
|
|---|
| 95 | /** Memory range type */
|
|---|
| 96 | typedef addr_range_list_t mem_range_list_t;
|
|---|
| 97 |
|
|---|
| 98 | /** HW resources parsed according to resource type */
|
|---|
| 99 | typedef struct hw_resource_list_parsed {
|
|---|
| 100 | /** List of IRQs */
|
|---|
| 101 | irq_list_t irqs;
|
|---|
| 102 |
|
|---|
| 103 | /** List of DMA channels */
|
|---|
| 104 | dma_list_t dma_channels;
|
|---|
| 105 |
|
|---|
| 106 | /** List of memory areas */
|
|---|
| 107 | mem_range_list_t mem_ranges;
|
|---|
| 108 |
|
|---|
| 109 | /** List of IO areas */
|
|---|
| 110 | io_range_list_t io_ranges;
|
|---|
| 111 | } hw_res_list_parsed_t;
|
|---|
| 112 |
|
|---|
| 113 | /** Clean hw_resource_list_parsed_t structure
|
|---|
| 114 | *
|
|---|
| 115 | * All allocated memory will be released, data amd pointers set to 0.
|
|---|
| 116 | *
|
|---|
| 117 | * @param list The structure to clear
|
|---|
| 118 | */
|
|---|
| 119 | static inline void hw_res_list_parsed_clean(hw_res_list_parsed_t *list)
|
|---|
| 120 | {
|
|---|
| 121 | if (list == NULL)
|
|---|
| 122 | return;
|
|---|
| 123 |
|
|---|
| 124 | free(list->irqs.irqs);
|
|---|
| 125 | free(list->io_ranges.ranges);
|
|---|
| 126 | free(list->mem_ranges.ranges);
|
|---|
| 127 | free(list->dma_channels.channels);
|
|---|
| 128 |
|
|---|
| 129 | bzero(list, sizeof(hw_res_list_parsed_t));
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | /** Initialize the hw_resource_list_parsed_t structure
|
|---|
| 133 | *
|
|---|
| 134 | * @param list The structure to initialize
|
|---|
| 135 | */
|
|---|
| 136 | static inline void hw_res_list_parsed_init(hw_res_list_parsed_t *list)
|
|---|
| 137 | {
|
|---|
| 138 | bzero(list, sizeof(hw_res_list_parsed_t));
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | extern int hw_res_list_parse(hw_resource_list_t *, hw_res_list_parsed_t *, int);
|
|---|
| 142 | extern int hw_res_get_list_parsed(async_sess_t *, hw_res_list_parsed_t *, int);
|
|---|
| 143 |
|
|---|
| 144 | #endif
|
|---|
| 145 |
|
|---|
| 146 | /** @}
|
|---|
| 147 | */
|
|---|