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