[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>
|
---|
[64d2b10] | 39 | #include <sys/types.h>
|
---|
[5b082ba9] | 40 | #include <sys/time.h>
|
---|
[c0699467] | 41 | #include <abi/ddi/irq.h>
|
---|
[a1e17fc] | 42 | #include <task.h>
|
---|
| 43 |
|
---|
[8442d10] | 44 | #define DMAMEM_16MiB ((uintptr_t) UINT64_C(0xffffffffff000000))
|
---|
| 45 | #define DMAMEM_4GiB ((uintptr_t) UINT64_C(0xffffffff00000000))
|
---|
| 46 |
|
---|
[84afc7b] | 47 | extern int device_assign_devno(void);
|
---|
[c6ae4c2] | 48 |
|
---|
[8442d10] | 49 | extern int physmem_map(uintptr_t, size_t, unsigned int, void **);
|
---|
[c6ae4c2] | 50 |
|
---|
[8442d10] | 51 | extern int dmamem_map(void *, size_t, unsigned int, unsigned int, uintptr_t *);
|
---|
| 52 | extern int dmamem_map_anonymous(size_t, uintptr_t, unsigned int, unsigned int,
|
---|
| 53 | uintptr_t *, void **);
|
---|
[fbcdeb8] | 54 | extern int dmamem_unmap(void *, size_t);
|
---|
[c6ae4c2] | 55 | extern int dmamem_unmap_anonymous(void *);
|
---|
| 56 |
|
---|
[0d5a50c] | 57 | extern int pio_enable(void *, size_t, void **);
|
---|
[5b082ba9] | 58 |
|
---|
[b5c2f56] | 59 | typedef void (*trace_fnc)(const volatile void *place, uint32_t val,
|
---|
[acc0efb] | 60 | volatile void* base, size_t size, void *data, bool write);
|
---|
| 61 |
|
---|
| 62 | extern int pio_trace_enable(void *, size_t, trace_fnc, void *);
|
---|
[b5c2f56] | 63 | extern void pio_trace_log(const volatile void *, uint32_t val, bool write);
|
---|
[acc0efb] | 64 | extern void pio_trace_disable(void *);
|
---|
| 65 |
|
---|
[3218648] | 66 | extern void pio_write_8(ioport8_t *, uint8_t);
|
---|
| 67 | extern void pio_write_16(ioport16_t *, uint16_t);
|
---|
| 68 | extern void pio_write_32(ioport32_t *, uint32_t);
|
---|
| 69 |
|
---|
[b5c2f56] | 70 | extern uint8_t pio_read_8(const ioport8_t *);
|
---|
| 71 | extern uint16_t pio_read_16(const ioport16_t *);
|
---|
| 72 | extern uint32_t pio_read_32(const ioport32_t *);
|
---|
[c6ae4c2] | 73 |
|
---|
[c67dbd6] | 74 | static inline uint8_t pio_change_8(ioport8_t *reg, uint8_t val, uint8_t mask,
|
---|
| 75 | useconds_t delay)
|
---|
[5b082ba9] | 76 | {
|
---|
| 77 | uint8_t v = pio_read_8(reg);
|
---|
| 78 | udelay(delay);
|
---|
| 79 | pio_write_8(reg, (v & ~mask) | val);
|
---|
| 80 | return v;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[c67dbd6] | 83 | static inline uint16_t pio_change_16(ioport16_t *reg, uint16_t val,
|
---|
| 84 | uint16_t mask, useconds_t delay)
|
---|
[5b082ba9] | 85 | {
|
---|
| 86 | uint16_t v = pio_read_16(reg);
|
---|
| 87 | udelay(delay);
|
---|
| 88 | pio_write_16(reg, (v & ~mask) | val);
|
---|
| 89 | return v;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[c67dbd6] | 92 | static inline uint32_t pio_change_32(ioport32_t *reg, uint32_t val,
|
---|
| 93 | uint32_t mask, useconds_t delay)
|
---|
[5b082ba9] | 94 | {
|
---|
| 95 | uint32_t v = pio_read_32(reg);
|
---|
| 96 | udelay(delay);
|
---|
| 97 | pio_write_32(reg, (v & ~mask) | val);
|
---|
| 98 | return v;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | static inline uint8_t pio_set_8(ioport8_t *r, uint8_t v, useconds_t d)
|
---|
| 102 | {
|
---|
| 103 | return pio_change_8(r, v, 0, d);
|
---|
| 104 | }
|
---|
| 105 | static inline uint16_t pio_set_16(ioport16_t *r, uint16_t v, useconds_t d)
|
---|
| 106 | {
|
---|
| 107 | return pio_change_16(r, v, 0, d);
|
---|
| 108 | }
|
---|
| 109 | static inline uint32_t pio_set_32(ioport32_t *r, uint32_t v, useconds_t d)
|
---|
| 110 | {
|
---|
| 111 | return pio_change_32(r, v, 0, d);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | static inline uint8_t pio_clear_8(ioport8_t *r, uint8_t v, useconds_t d)
|
---|
| 115 | {
|
---|
| 116 | return pio_change_8(r, 0, v, d);
|
---|
| 117 | }
|
---|
| 118 | static inline uint16_t pio_clear_16(ioport16_t *r, uint16_t v, useconds_t d)
|
---|
| 119 | {
|
---|
| 120 | return pio_change_16(r, 0, v, d);
|
---|
| 121 | }
|
---|
| 122 | static inline uint32_t pio_clear_32(ioport32_t *r, uint32_t v, useconds_t d)
|
---|
| 123 | {
|
---|
| 124 | return pio_change_32(r, 0, v, d);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[f044e96] | 127 | extern int irq_register(int, int, int, irq_code_t *);
|
---|
| 128 | extern int irq_unregister(int, int);
|
---|
[a1e17fc] | 129 |
|
---|
| 130 | #endif
|
---|
[b2951e2] | 131 |
|
---|
[fadd381] | 132 | /** @}
|
---|
[b2951e2] | 133 | */
|
---|