[a1e17fc] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Jakub Jermar
|
---|
[a1e17fc] | 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 |
|
---|
[fadd381] | 29 | /** @addtogroup libc
|
---|
[b2951e2] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[fadd381] | 35 | #ifndef LIBC_DDI_H_
|
---|
| 36 | #define LIBC_DDI_H_
|
---|
[a1e17fc] | 37 |
|
---|
[3e6a98c5] | 38 | #include <stdbool.h>
|
---|
[7ee7e6a] | 39 | #include <stddef.h>
|
---|
| 40 | #include <stdint.h>
|
---|
[5b082ba9] | 41 | #include <sys/time.h>
|
---|
[c0699467] | 42 | #include <abi/ddi/irq.h>
|
---|
[eeb5cc2] | 43 | #include <device/hw_res.h>
|
---|
[8049b79] | 44 | #include <device/hw_res_parsed.h>
|
---|
[eeb5cc2] | 45 | #include <device/pio_window.h>
|
---|
[a1e17fc] | 46 | #include <task.h>
|
---|
| 47 |
|
---|
[8442d10] | 48 | #define DMAMEM_16MiB ((uintptr_t) UINT64_C(0xffffffffff000000))
|
---|
| 49 | #define DMAMEM_4GiB ((uintptr_t) UINT64_C(0xffffffff00000000))
|
---|
| 50 |
|
---|
[7ee7e6a] | 51 | typedef volatile uint8_t ioport8_t;
|
---|
| 52 | typedef volatile uint16_t ioport16_t;
|
---|
| 53 | typedef volatile uint32_t ioport32_t;
|
---|
[aa537a5a] | 54 | typedef volatile uint64_t ioport64_t;
|
---|
[7ee7e6a] | 55 |
|
---|
[8442d10] | 56 | extern int physmem_map(uintptr_t, size_t, unsigned int, void **);
|
---|
[8cd680c] | 57 | extern int physmem_unmap(void *);
|
---|
[c6ae4c2] | 58 |
|
---|
[8442d10] | 59 | extern int dmamem_map(void *, size_t, unsigned int, unsigned int, uintptr_t *);
|
---|
| 60 | extern int dmamem_map_anonymous(size_t, uintptr_t, unsigned int, unsigned int,
|
---|
| 61 | uintptr_t *, void **);
|
---|
[fbcdeb8] | 62 | extern int dmamem_unmap(void *, size_t);
|
---|
[c6ae4c2] | 63 | extern int dmamem_unmap_anonymous(void *);
|
---|
| 64 |
|
---|
[8049b79] | 65 | extern int pio_enable_range(addr_range_t *, void **);
|
---|
[eeb5cc2] | 66 | extern int pio_enable_resource(pio_window_t *, hw_resource_t *, void **);
|
---|
[0d5a50c] | 67 | extern int pio_enable(void *, size_t, void **);
|
---|
[8cd680c] | 68 | extern int pio_disable(void *, size_t);
|
---|
[5b082ba9] | 69 |
|
---|
[aa537a5a] | 70 | typedef void (*trace_fnc)(const volatile void *place, uint64_t val,
|
---|
[acc0efb] | 71 | volatile void* base, size_t size, void *data, bool write);
|
---|
| 72 |
|
---|
| 73 | extern int pio_trace_enable(void *, size_t, trace_fnc, void *);
|
---|
[aa537a5a] | 74 | extern void pio_trace_log(const volatile void *, uint64_t val, bool write);
|
---|
[acc0efb] | 75 | extern void pio_trace_disable(void *);
|
---|
| 76 |
|
---|
[3218648] | 77 | extern void pio_write_8(ioport8_t *, uint8_t);
|
---|
| 78 | extern void pio_write_16(ioport16_t *, uint16_t);
|
---|
| 79 | extern void pio_write_32(ioport32_t *, uint32_t);
|
---|
[aa537a5a] | 80 | extern void pio_write_64(ioport64_t *, uint64_t);
|
---|
[3218648] | 81 |
|
---|
[b5c2f56] | 82 | extern uint8_t pio_read_8(const ioport8_t *);
|
---|
| 83 | extern uint16_t pio_read_16(const ioport16_t *);
|
---|
| 84 | extern uint32_t pio_read_32(const ioport32_t *);
|
---|
[aa537a5a] | 85 | extern uint64_t pio_read_64(const ioport64_t *);
|
---|
[c6ae4c2] | 86 |
|
---|
[c67dbd6] | 87 | static inline uint8_t pio_change_8(ioport8_t *reg, uint8_t val, uint8_t mask,
|
---|
| 88 | useconds_t delay)
|
---|
[5b082ba9] | 89 | {
|
---|
| 90 | uint8_t v = pio_read_8(reg);
|
---|
| 91 | udelay(delay);
|
---|
| 92 | pio_write_8(reg, (v & ~mask) | val);
|
---|
| 93 | return v;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[c67dbd6] | 96 | static inline uint16_t pio_change_16(ioport16_t *reg, uint16_t val,
|
---|
| 97 | uint16_t mask, useconds_t delay)
|
---|
[5b082ba9] | 98 | {
|
---|
| 99 | uint16_t v = pio_read_16(reg);
|
---|
| 100 | udelay(delay);
|
---|
| 101 | pio_write_16(reg, (v & ~mask) | val);
|
---|
| 102 | return v;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[c67dbd6] | 105 | static inline uint32_t pio_change_32(ioport32_t *reg, uint32_t val,
|
---|
| 106 | uint32_t mask, useconds_t delay)
|
---|
[5b082ba9] | 107 | {
|
---|
| 108 | uint32_t v = pio_read_32(reg);
|
---|
| 109 | udelay(delay);
|
---|
| 110 | pio_write_32(reg, (v & ~mask) | val);
|
---|
| 111 | return v;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[aa537a5a] | 114 | static inline uint64_t pio_change_64(ioport64_t *reg, uint64_t val,
|
---|
| 115 | uint64_t mask, useconds_t delay)
|
---|
| 116 | {
|
---|
| 117 | uint64_t v = pio_read_64(reg);
|
---|
| 118 | udelay(delay);
|
---|
| 119 | pio_write_64(reg, (v & ~mask) | val);
|
---|
| 120 | return v;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[5b082ba9] | 123 | static inline uint8_t pio_set_8(ioport8_t *r, uint8_t v, useconds_t d)
|
---|
| 124 | {
|
---|
| 125 | return pio_change_8(r, v, 0, d);
|
---|
| 126 | }
|
---|
| 127 | static inline uint16_t pio_set_16(ioport16_t *r, uint16_t v, useconds_t d)
|
---|
| 128 | {
|
---|
| 129 | return pio_change_16(r, v, 0, d);
|
---|
| 130 | }
|
---|
| 131 | static inline uint32_t pio_set_32(ioport32_t *r, uint32_t v, useconds_t d)
|
---|
| 132 | {
|
---|
| 133 | return pio_change_32(r, v, 0, d);
|
---|
| 134 | }
|
---|
[aa537a5a] | 135 | static inline uint64_t pio_set_64(ioport64_t *r, uint64_t v, useconds_t d)
|
---|
| 136 | {
|
---|
| 137 | return pio_change_64(r, v, 0, d);
|
---|
| 138 | }
|
---|
[5b082ba9] | 139 |
|
---|
| 140 | static inline uint8_t pio_clear_8(ioport8_t *r, uint8_t v, useconds_t d)
|
---|
| 141 | {
|
---|
| 142 | return pio_change_8(r, 0, v, d);
|
---|
| 143 | }
|
---|
| 144 | static inline uint16_t pio_clear_16(ioport16_t *r, uint16_t v, useconds_t d)
|
---|
| 145 | {
|
---|
| 146 | return pio_change_16(r, 0, v, d);
|
---|
| 147 | }
|
---|
| 148 | static inline uint32_t pio_clear_32(ioport32_t *r, uint32_t v, useconds_t d)
|
---|
| 149 | {
|
---|
| 150 | return pio_change_32(r, 0, v, d);
|
---|
| 151 | }
|
---|
[aa537a5a] | 152 | static inline uint64_t pio_clear_64(ioport64_t *r, uint64_t v, useconds_t d)
|
---|
| 153 | {
|
---|
| 154 | return pio_change_64(r, 0, v, d);
|
---|
| 155 | }
|
---|
[5b082ba9] | 156 |
|
---|
[a1e17fc] | 157 | #endif
|
---|
[b2951e2] | 158 |
|
---|
[fadd381] | 159 | /** @}
|
---|
[b2951e2] | 160 | */
|
---|