source: mainline/uspace/lib/c/include/ddi.h

Last change on this file was dc5647e, checked in by Jiri Svoboda <jiri@…>, 12 months ago

PC floppy disk driver

Bare minimum implemented.

  • Property mode set to 100644
File size: 6.4 KB
RevLine 
[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
[4805495]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>
[bd41ac52]41#include <time.h>
[85be731]42#include <byteorder.h>
[c0699467]43#include <abi/ddi/irq.h>
[eeb5cc2]44#include <device/hw_res.h>
[8049b79]45#include <device/hw_res_parsed.h>
[eeb5cc2]46#include <device/pio_window.h>
[a1e17fc]47#include <task.h>
48
[dc5647e]49#define DMAMEM_1MiB ((uintptr_t) UINT64_C(0xfffffffffff00000))
[8442d10]50#define DMAMEM_16MiB ((uintptr_t) UINT64_C(0xffffffffff000000))
51#define DMAMEM_4GiB ((uintptr_t) UINT64_C(0xffffffff00000000))
52
[7ee7e6a]53typedef volatile uint8_t ioport8_t;
54typedef volatile uint16_t ioport16_t;
55typedef volatile uint32_t ioport32_t;
[aa537a5a]56typedef volatile uint64_t ioport64_t;
[7ee7e6a]57
[b7fd2a0]58extern errno_t physmem_map(uintptr_t, size_t, unsigned int, void **);
59extern errno_t physmem_unmap(void *);
[c6ae4c2]60
[b7fd2a0]61extern errno_t dmamem_map(void *, size_t, unsigned int, unsigned int, uintptr_t *);
62extern errno_t dmamem_map_anonymous(size_t, uintptr_t, unsigned int, unsigned int,
[8442d10]63 uintptr_t *, void **);
[b7fd2a0]64extern errno_t dmamem_unmap(void *, size_t);
65extern errno_t dmamem_unmap_anonymous(void *);
[c6ae4c2]66
[b7fd2a0]67extern errno_t pio_enable_range(addr_range_t *, void **);
[9e9ced0]68extern errno_t pio_enable_resource(pio_window_t *, hw_resource_t *, void **,
[848e880f]69 uintptr_t *, size_t *);
[b7fd2a0]70extern errno_t pio_enable(void *, size_t, void **);
71extern errno_t pio_disable(void *, size_t);
[5b082ba9]72
[aa537a5a]73typedef void (*trace_fnc)(const volatile void *place, uint64_t val,
[1433ecda]74 volatile void *base, size_t size, void *data, bool write);
[acc0efb]75
[b7fd2a0]76extern errno_t pio_trace_enable(void *, size_t, trace_fnc, void *);
[aa537a5a]77extern void pio_trace_log(const volatile void *, uint64_t val, bool write);
[acc0efb]78extern void pio_trace_disable(void *);
79
[3218648]80extern void pio_write_8(ioport8_t *, uint8_t);
81extern void pio_write_16(ioport16_t *, uint16_t);
82extern void pio_write_32(ioport32_t *, uint32_t);
[aa537a5a]83extern void pio_write_64(ioport64_t *, uint64_t);
[3218648]84
[b5c2f56]85extern uint8_t pio_read_8(const ioport8_t *);
86extern uint16_t pio_read_16(const ioport16_t *);
87extern uint32_t pio_read_32(const ioport32_t *);
[aa537a5a]88extern uint64_t pio_read_64(const ioport64_t *);
[c6ae4c2]89
[85be731]90static inline void pio_write_le16(ioport16_t *reg, uint16_t val)
91{
92 pio_write_16(reg, host2uint16_t_le(val));
93}
94static inline void pio_write_be16(ioport16_t *reg, uint16_t val)
95{
96 pio_write_16(reg, host2uint16_t_be(val));
97}
98static inline void pio_write_le32(ioport32_t *reg, uint32_t val)
99{
100 pio_write_32(reg, host2uint32_t_le(val));
101}
102static inline void pio_write_be32(ioport32_t *reg, uint32_t val)
103{
104 pio_write_32(reg, host2uint32_t_be(val));
105}
106static inline void pio_write_le64(ioport64_t *reg, uint64_t val)
107{
108 pio_write_64(reg, host2uint64_t_le(val));
109}
110static inline void pio_write_be64(ioport64_t *reg, uint64_t val)
111{
112 pio_write_64(reg, host2uint64_t_be(val));
113}
114
115static inline uint16_t pio_read_le16(const ioport16_t *reg)
116{
117 return uint16_t_le2host(pio_read_16(reg));
118}
119static inline uint16_t pio_read_be16(const ioport16_t *reg)
120{
121 return uint16_t_be2host(pio_read_16(reg));
122}
123static inline uint32_t pio_read_le32(const ioport32_t *reg)
124{
125 return uint32_t_le2host(pio_read_32(reg));
126}
127static inline uint32_t pio_read_be32(const ioport32_t *reg)
128{
129 return uint32_t_be2host(pio_read_32(reg));
130}
131static inline uint64_t pio_read_le64(const ioport64_t *reg)
132{
133 return uint64_t_le2host(pio_read_64(reg));
134}
135static inline uint64_t pio_read_be64(const ioport64_t *reg)
136{
137 return uint64_t_be2host(pio_read_64(reg));
138}
139
[c67dbd6]140static inline uint8_t pio_change_8(ioport8_t *reg, uint8_t val, uint8_t mask,
[bd41ac52]141 usec_t delay)
[5b082ba9]142{
143 uint8_t v = pio_read_8(reg);
144 udelay(delay);
145 pio_write_8(reg, (v & ~mask) | val);
146 return v;
147}
148
[c67dbd6]149static inline uint16_t pio_change_16(ioport16_t *reg, uint16_t val,
[bd41ac52]150 uint16_t mask, usec_t delay)
[5b082ba9]151{
152 uint16_t v = pio_read_16(reg);
153 udelay(delay);
154 pio_write_16(reg, (v & ~mask) | val);
155 return v;
156}
157
[c67dbd6]158static inline uint32_t pio_change_32(ioport32_t *reg, uint32_t val,
[bd41ac52]159 uint32_t mask, usec_t delay)
[5b082ba9]160{
161 uint32_t v = pio_read_32(reg);
162 udelay(delay);
163 pio_write_32(reg, (v & ~mask) | val);
164 return v;
165}
166
[aa537a5a]167static inline uint64_t pio_change_64(ioport64_t *reg, uint64_t val,
[bd41ac52]168 uint64_t mask, usec_t delay)
[aa537a5a]169{
170 uint64_t v = pio_read_64(reg);
171 udelay(delay);
172 pio_write_64(reg, (v & ~mask) | val);
173 return v;
174}
175
[bd41ac52]176static inline uint8_t pio_set_8(ioport8_t *r, uint8_t v, usec_t d)
[5b082ba9]177{
178 return pio_change_8(r, v, 0, d);
179}
[bd41ac52]180static inline uint16_t pio_set_16(ioport16_t *r, uint16_t v, usec_t d)
[5b082ba9]181{
182 return pio_change_16(r, v, 0, d);
183}
[bd41ac52]184static inline uint32_t pio_set_32(ioport32_t *r, uint32_t v, usec_t d)
[5b082ba9]185{
186 return pio_change_32(r, v, 0, d);
187}
[bd41ac52]188static inline uint64_t pio_set_64(ioport64_t *r, uint64_t v, usec_t d)
[aa537a5a]189{
190 return pio_change_64(r, v, 0, d);
191}
[5b082ba9]192
[bd41ac52]193static inline uint8_t pio_clear_8(ioport8_t *r, uint8_t v, usec_t d)
[5b082ba9]194{
195 return pio_change_8(r, 0, v, d);
196}
[bd41ac52]197static inline uint16_t pio_clear_16(ioport16_t *r, uint16_t v, usec_t d)
[5b082ba9]198{
199 return pio_change_16(r, 0, v, d);
200}
[bd41ac52]201static inline uint32_t pio_clear_32(ioport32_t *r, uint32_t v, usec_t d)
[5b082ba9]202{
203 return pio_change_32(r, 0, v, d);
204}
[bd41ac52]205static inline uint64_t pio_clear_64(ioport64_t *r, uint64_t v, usec_t d)
[aa537a5a]206{
207 return pio_change_64(r, 0, v, d);
208}
[5b082ba9]209
[a1e17fc]210#endif
[b2951e2]211
[fadd381]212/** @}
[b2951e2]213 */
Note: See TracBrowser for help on using the repository browser.