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