source: mainline/uspace/lib/c/include/device/hw_res.h@ acb14ce

Last change on this file since acb14ce was 443695e, checked in by Jiri Svoboda <jiri@…>, 19 months ago

Basic PCI-IDE driver (no DMA support)

Also, make sure we avoid attaching ISA IDE and PCI IDE
at the same time. For simplicity, use ISA IDE on ISA systems
and PCI IDE on PCI-based systems.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2024 Jiri Svoboda
3 * Copyright (c) 2010 Lenka Trochtova
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libc
31 * @{
32 */
33/** @file
34 */
35
36#ifndef _LIBC_DEVICE_HW_RES_H_
37#define _LIBC_DEVICE_HW_RES_H_
38
39#include <ipc/dev_iface.h>
40#include <async.h>
41#include <stdbool.h>
42
43#define DMA_MODE_ON_DEMAND 0
44#define DMA_MODE_WRITE (1 << 2)
45#define DMA_MODE_READ (1 << 3)
46#define DMA_MODE_AUTO (1 << 4)
47#define DMA_MODE_DOWN (1 << 5)
48#define DMA_MODE_SINGLE (1 << 6)
49#define DMA_MODE_BLOCK (1 << 7)
50
51/** HW resource provider interface */
52typedef enum {
53 HW_RES_GET_RESOURCE_LIST = 0,
54 HW_RES_ENABLE_INTERRUPT,
55 HW_RES_DISABLE_INTERRUPT,
56 HW_RES_CLEAR_INTERRUPT,
57 HW_RES_DMA_CHANNEL_SETUP,
58 HW_RES_DMA_CHANNEL_REMAIN,
59 HW_RES_GET_FLAGS
60} hw_res_method_t;
61
62/** HW resource types */
63typedef enum {
64 INTERRUPT,
65 IO_RANGE,
66 MEM_RANGE,
67 DMA_CHANNEL_8,
68 DMA_CHANNEL_16,
69} hw_res_type_t;
70
71typedef enum {
72 LITTLE_ENDIAN = 0,
73 BIG_ENDIAN
74} endianness_t;
75
76/** HW resource (e.g. interrupt, memory register, i/o register etc.) */
77typedef struct {
78 hw_res_type_t type;
79 union {
80 struct {
81 uint64_t address;
82 size_t size;
83 bool relative;
84 endianness_t endianness;
85 } mem_range;
86
87 struct {
88 uint64_t address;
89 size_t size;
90 bool relative;
91 endianness_t endianness;
92 } io_range;
93
94 struct {
95 int irq;
96 } interrupt;
97
98 union {
99 unsigned int dma8;
100 unsigned int dma16;
101 } dma_channel;
102 } res;
103} hw_resource_t;
104
105typedef struct {
106 size_t count;
107 hw_resource_t *resources;
108} hw_resource_list_t;
109
110static inline void hw_res_clean_resource_list(hw_resource_list_t *hw_res)
111{
112 if (hw_res->resources != NULL) {
113 free(hw_res->resources);
114 hw_res->resources = NULL;
115 }
116
117 hw_res->count = 0;
118}
119
120typedef enum {
121 /** This is an PCI/ISA bridge, not 'classic' ISA bus */
122 hwf_isa_bridge = 0x1
123} hw_res_flags_t;
124
125extern errno_t hw_res_get_resource_list(async_sess_t *, hw_resource_list_t *);
126extern errno_t hw_res_enable_interrupt(async_sess_t *, int);
127extern errno_t hw_res_disable_interrupt(async_sess_t *, int);
128extern errno_t hw_res_clear_interrupt(async_sess_t *, int);
129
130extern errno_t hw_res_dma_channel_setup(async_sess_t *, unsigned int, uint32_t,
131 uint32_t, uint8_t);
132extern errno_t hw_res_dma_channel_remain(async_sess_t *, unsigned, size_t *);
133extern errno_t hw_res_get_flags(async_sess_t *, hw_res_flags_t *);
134
135#endif
136
137/** @}
138 */
Note: See TracBrowser for help on using the repository browser.