1f9f848faSopenharmony_ci/*-
2f9f848faSopenharmony_ci * Copyright (c) 2011 Hans Petter Selasky. All rights reserved.
3f9f848faSopenharmony_ci *
4f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without
5f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions
6f9f848faSopenharmony_ci * are met:
7f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright
8f9f848faSopenharmony_ci *    notice, this list of conditions and the following disclaimer.
9f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
10f9f848faSopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
11f9f848faSopenharmony_ci *    documentation and/or other materials provided with the distribution.
12f9f848faSopenharmony_ci *
13f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14f9f848faSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15f9f848faSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16f9f848faSopenharmony_ci * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17f9f848faSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18f9f848faSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19f9f848faSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20f9f848faSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21f9f848faSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22f9f848faSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23f9f848faSopenharmony_ci * SUCH DAMAGE.
24f9f848faSopenharmony_ci */
25f9f848faSopenharmony_ci
26f9f848faSopenharmony_ci#ifndef _BSD_KERNEL_H_
27f9f848faSopenharmony_ci#define	_BSD_KERNEL_H_
28f9f848faSopenharmony_ci
29f9f848faSopenharmony_ci#include <los_typedef.h>
30f9f848faSopenharmony_ci#include <stdint.h>
31f9f848faSopenharmony_ci
32f9f848faSopenharmony_ci#define	_KERNEL
33f9f848faSopenharmony_ci#include "sys/module.h"
34f9f848faSopenharmony_ci#include "sys/bus.h"
35f9f848faSopenharmony_ci
36f9f848faSopenharmony_ci#define	__FreeBSD_version 1000000
37f9f848faSopenharmony_ci
38f9f848faSopenharmony_ci#define	rebooting 0
39f9f848faSopenharmony_ci#define	M_USB 0
40f9f848faSopenharmony_ci#define	M_USBDEV 0
41f9f848faSopenharmony_ci#define	USB_PROC_MAX 3
42f9f848faSopenharmony_ci#define	M_DEVBUF 1
43f9f848faSopenharmony_ci
44f9f848faSopenharmony_ci
45f9f848faSopenharmony_ci#define	SYSCTL_DECL(...)
46f9f848faSopenharmony_ci#define	SYSCTL_INT(...)
47f9f848faSopenharmony_ci#define	TUNABLE_INT(...)
48f9f848faSopenharmony_ci#define	EVENTHANDLER_DECLARE(...)
49f9f848faSopenharmony_ci#define	EVENTHANDLER_INVOKE(...)
50f9f848faSopenharmony_ci#define	SCHEDULER_STOPPED(x) (0)
51f9f848faSopenharmony_ci#define	PI_SWI(...) (0)
52f9f848faSopenharmony_ci#define	UNIQ_NAME(x) x
53f9f848faSopenharmony_ci#define	UNIQ_NAME_STR(x) #x
54f9f848faSopenharmony_ci
55f9f848faSopenharmony_ci#define	hz  LOSCFG_BASE_CORE_TICK_PER_SECOND
56f9f848faSopenharmony_ci#ifndef PAGE_SIZE
57f9f848faSopenharmony_ci#define	PAGE_SIZE 4096
58f9f848faSopenharmony_ci#endif
59f9f848faSopenharmony_ci
60f9f848faSopenharmony_citypedef unsigned long bus_addr_t;
61f9f848faSopenharmony_citypedef unsigned long bus_size_t;
62f9f848faSopenharmony_ci
63f9f848faSopenharmony_citypedef void *bus_dmamap_t;
64f9f848faSopenharmony_citypedef void *bus_dma_tag_t;
65f9f848faSopenharmony_ci
66f9f848faSopenharmony_citypedef unsigned long bus_space_handle_t;
67f9f848faSopenharmony_ci
68f9f848faSopenharmony_citypedef struct bus_dma_segment {
69f9f848faSopenharmony_ci	bus_addr_t	ds_addr;	/* DMA address */
70f9f848faSopenharmony_ci	bus_size_t	ds_len;		/* length of transfer */
71f9f848faSopenharmony_ci} bus_dma_segment_t;
72f9f848faSopenharmony_ci
73f9f848faSopenharmony_citypedef enum {
74f9f848faSopenharmony_ci	BUS_DMA_LOCK	= 0x01,
75f9f848faSopenharmony_ci	BUS_DMA_UNLOCK	= 0x02,
76f9f848faSopenharmony_ci} bus_dma_lock_op_t;
77f9f848faSopenharmony_ci
78f9f848faSopenharmony_ciextern struct mtx Giant;
79f9f848faSopenharmony_ci
80f9f848faSopenharmony_ci#define CUR_TICKS (LOS_TickCountGet() & 0xFFFFFFFF)
81f9f848faSopenharmony_ci
82f9f848faSopenharmony_ci#ifdef LOSCFG_USB_DEBUG
83f9f848faSopenharmony_ci#define DEBUG_MODULE(name, func)        \
84f9f848faSopenharmony_ci/*   static  */struct debug_module_data debug_##name##_mod = {  \
85f9f848faSopenharmony_ci        func, #name, { 0, 0 } };
86f9f848faSopenharmony_ci
87f9f848faSopenharmony_cistruct debug_module_data {
88f9f848faSopenharmony_ci        void    (*callback) (int arg);
89f9f848faSopenharmony_ci        const char *mod_name;
90f9f848faSopenharmony_ci        TAILQ_ENTRY(debug_module_data) entry;
91f9f848faSopenharmony_ci};
92f9f848faSopenharmony_ci
93f9f848faSopenharmony_civoid debug_module_register(void *data);
94f9f848faSopenharmony_civoid debug_module_unregister(void *data);
95f9f848faSopenharmony_cistruct debug_module_data *get_debug_module(const char *modname);
96f9f848faSopenharmony_civoid debug_module_dump(void);
97f9f848faSopenharmony_ci
98f9f848faSopenharmony_ci#define usb_debug(fmt, ...) \
99f9f848faSopenharmony_ci	dprintf("[USB_DEBUG]: In %s %d, " fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__);
100f9f848faSopenharmony_ci#else
101f9f848faSopenharmony_ci#define usb_debug(fmt, ...)
102f9f848faSopenharmony_ci#endif
103f9f848faSopenharmony_ci
104f9f848faSopenharmony_ci#define usb_err(fmt, ...) \
105f9f848faSopenharmony_ci	dprintf("[USB_ERR]: In %s %d, " fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__);
106f9f848faSopenharmony_ci
107f9f848faSopenharmony_ci#define	device_printf(dev, fmt,...) \
108f9f848faSopenharmony_ci	dprintf("%s (%s): " fmt, __FUNCTION__, device_get_nameunit(dev), ##__VA_ARGS__)
109f9f848faSopenharmony_ci
110f9f848faSopenharmony_ci#define	bus_get_dma_tag(...) (NULL)
111f9f848faSopenharmony_ci
112f9f848faSopenharmony_ci/* BUS SPACE API */
113f9f848faSopenharmony_ci
114f9f848faSopenharmony_civoid module_register(void *);
115f9f848faSopenharmony_civoid module_unregister(void *);
116f9f848faSopenharmony_ci/* USB */
117f9f848faSopenharmony_ci
118f9f848faSopenharmony_citypedef int usb_handle_request_t (device_t dev, const void *req, void **pptr, uint16_t *plen,
119f9f848faSopenharmony_ci								    uint16_t offset, uint8_t *pstate);
120f9f848faSopenharmony_citypedef int usb_take_controller_t (device_t dev);
121f9f848faSopenharmony_ci
122f9f848faSopenharmony_ci/* set some defaults */
123f9f848faSopenharmony_ci
124f9f848faSopenharmony_ci#ifndef USB_POOL_SIZE
125f9f848faSopenharmony_ci#define	USB_POOL_SIZE (1024*1024)	/* 1 MByte */
126f9f848faSopenharmony_ci#endif
127f9f848faSopenharmony_ci
128f9f848faSopenharmony_ci#ifndef	__DECONST
129f9f848faSopenharmony_ci#define	__DECONST(type, var)	((type)(__uintptr_t)(const void *)(var))
130f9f848faSopenharmony_ci#endif
131f9f848faSopenharmony_ci
132f9f848faSopenharmony_ci/* BUS SPACE API */
133f9f848faSopenharmony_civoid	bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t data);
134f9f848faSopenharmony_civoid	bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t data);
135f9f848faSopenharmony_civoid	bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t data);
136f9f848faSopenharmony_ci
137f9f848faSopenharmony_ciuint8_t	bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
138f9f848faSopenharmony_ciuint16_t bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
139f9f848faSopenharmony_ciuint32_t bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
140f9f848faSopenharmony_ci
141f9f848faSopenharmony_civoid	bus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset,
142f9f848faSopenharmony_ci							    uint8_t *datap, bus_size_t count);
143f9f848faSopenharmony_civoid	bus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset,
144f9f848faSopenharmony_ci							    uint16_t *datap, bus_size_t count);
145f9f848faSopenharmony_civoid	bus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset,
146f9f848faSopenharmony_ci							    uint32_t *datap, bus_size_t count);
147f9f848faSopenharmony_ci
148f9f848faSopenharmony_civoid	bus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset,
149f9f848faSopenharmony_ci							    uint8_t *datap, bus_size_t count);
150f9f848faSopenharmony_civoid	bus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset,
151f9f848faSopenharmony_ci							    uint16_t *datap, bus_size_t count);
152f9f848faSopenharmony_civoid	bus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset,
153f9f848faSopenharmony_ci							    uint32_t *datap, bus_size_t count);
154f9f848faSopenharmony_ci
155f9f848faSopenharmony_civoid	bus_space_read_region_1(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset,
156f9f848faSopenharmony_ci							    uint8_t *datap, bus_size_t count);
157f9f848faSopenharmony_civoid	bus_space_write_region_1(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset,
158f9f848faSopenharmony_ci							    uint8_t *datap, bus_size_t count);
159f9f848faSopenharmony_civoid	bus_space_read_region_4(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset,
160f9f848faSopenharmony_ci							    uint32_t *datap, bus_size_t count);
161f9f848faSopenharmony_civoid	bus_space_write_region_4(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset,
162f9f848faSopenharmony_ci							    uint32_t *datap, bus_size_t count);
163f9f848faSopenharmony_ci
164f9f848faSopenharmony_ciextern void devclass_module_dump(void);
165f9f848faSopenharmony_ci
166f9f848faSopenharmony_ci#endif					/* _BSD_KERNEL_H_ */
167