| 1 |
#ifndef XDEFS_H |
| 2 |
#define XDEFS_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#ifdef __KERNEL__ |
| 26 |
|
| 27 |
#include <linux/kernel.h> |
| 28 |
#include <linux/version.h> |
| 29 |
|
| 30 |
#else |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#include <stdint.h> |
| 35 |
typedef uint8_t __u8; |
| 36 |
typedef uint32_t __u32; |
| 37 |
|
| 38 |
#include <stdio.h> |
| 39 |
|
| 40 |
#define DBG(fmt, ...) printf("DBG: %s: " fmt, __func__, ## __VA_ARGS__) |
| 41 |
#define INFO(fmt, ...) printf("INFO: " fmt, ## __VA_ARGS__) |
| 42 |
#define NOTICE(fmt, ...) printf("NOTICE: " fmt, ## __VA_ARGS__) |
| 43 |
#define ERR(fmt, ...) printf("ERR: " fmt, ## __VA_ARGS__) |
| 44 |
#define __user |
| 45 |
|
| 46 |
struct list_head { |
| 47 |
struct list_head *next; |
| 48 |
struct list_head *prev; |
| 49 |
}; |
| 50 |
|
| 51 |
#endif |
| 52 |
|
| 53 |
#define PACKED __attribute__((packed)) |
| 54 |
|
| 55 |
#define ALL_LINES ((lineno_t)-1) |
| 56 |
|
| 57 |
#ifndef BIT |
| 58 |
#define BIT(i) (1UL << (i)) |
| 59 |
#endif |
| 60 |
#define BIT_SET(x, i) ((x) |= BIT(i)) |
| 61 |
#define BIT_CLR(x, i) ((x) &= ~BIT(i)) |
| 62 |
#define IS_SET(x, i) (((x) & BIT(i)) != 0) |
| 63 |
#define BITMASK(i) (((u64)1 << (i)) - 1) |
| 64 |
|
| 65 |
#define MAX_PROC_WRITE 100 |
| 66 |
#define CHANNELS_PERXPD 32 |
| 67 |
|
| 68 |
#define MAX_SPANNAME 20 |
| 69 |
#define MAX_SPANDESC 40 |
| 70 |
#define MAX_CHANNAME 40 |
| 71 |
|
| 72 |
#define XPD_NAMELEN 10 |
| 73 |
#define XPD_DESCLEN 20 |
| 74 |
#define XBUS_NAMELEN 20 |
| 75 |
#define XBUS_DESCLEN 40 |
| 76 |
#define LABEL_SIZE 20 |
| 77 |
|
| 78 |
#define UNIT_BITS 3 |
| 79 |
#define SUBUNIT_BITS 3 |
| 80 |
|
| 81 |
|
| 82 |
#define MAX_UNIT (1 << UNIT_BITS) |
| 83 |
#define MAX_SUBUNIT (1 << SUBUNIT_BITS) |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
#if MAX_UNIT > BIT(UNIT_BITS) |
| 89 |
#error "MAX_UNIT too large" |
| 90 |
#endif |
| 91 |
|
| 92 |
#if MAX_SUBUNIT > BIT(SUBUNIT_BITS) |
| 93 |
#error "MAX_SUBUNIT too large" |
| 94 |
#endif |
| 95 |
|
| 96 |
#define MAX_XPDS (MAX_UNIT*MAX_SUBUNIT) |
| 97 |
|
| 98 |
#define VALID_XPD_NUM(x) ((x) < MAX_XPDS && (x) >= 0) |
| 99 |
|
| 100 |
#define CHAN_BITS 5 |
| 101 |
|
| 102 |
typedef char *charp; |
| 103 |
#ifdef __KERNEL__ |
| 104 |
|
| 105 |
|
| 106 |
#define KMEM_CACHE_T struct kmem_cache |
| 107 |
|
| 108 |
#define KZALLOC(size, gfp) my_kzalloc(size, gfp) |
| 109 |
#define KZFREE(p) \ |
| 110 |
do { \ |
| 111 |
memset((p), 0, sizeof(*(p))); \ |
| 112 |
kfree(p); \ |
| 113 |
} while (0); |
| 114 |
|
| 115 |
#define DEVICE_ATTR_READER(name, dev, buf) \ |
| 116 |
ssize_t name(struct device *dev, \ |
| 117 |
struct device_attribute *attr, char *buf) |
| 118 |
#define DEVICE_ATTR_WRITER(name, dev, buf, count) \ |
| 119 |
ssize_t name(struct device *dev, \ |
| 120 |
struct device_attribute *attr, \ |
| 121 |
const char *buf, size_t count) |
| 122 |
#define DRIVER_ATTR_READER(name, drv, buf) \ |
| 123 |
ssize_t name(struct device_driver *drv, char * buf) |
| 124 |
|
| 125 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) |
| 126 |
#define SET_PROC_DIRENTRY_OWNER(p) \ |
| 127 |
do { \ |
| 128 |
(p)->owner = THIS_MODULE; \ |
| 129 |
} while (0); |
| 130 |
#else |
| 131 |
#define SET_PROC_DIRENTRY_OWNER(p) do { } while (0); |
| 132 |
#endif |
| 133 |
|
| 134 |
#else |
| 135 |
typedef int bool; |
| 136 |
#endif |
| 137 |
typedef struct xbus xbus_t; |
| 138 |
typedef struct xpd xpd_t; |
| 139 |
typedef struct xframe xframe_t; |
| 140 |
typedef struct xpacket xpacket_t; |
| 141 |
typedef __u32 xpp_line_t; |
| 142 |
typedef __u8 lineno_t; |
| 143 |
typedef __u8 xportno_t; |
| 144 |
|
| 145 |
#define PORT_BROADCAST 255 |
| 146 |
|
| 147 |
#endif |