1 /* 2 * Copyright 2007, Hugo Santos. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Hugo Santos, hugosantos@gmail.com 7 * 8 * Some of this code is based on previous work by Marcus Overhagen. 9 */ 10 #ifndef _DEVICE_H_ 11 #define _DEVICE_H_ 12 13 #include <stdint.h> 14 #include <stdio.h> 15 16 #include <KernelExport.h> 17 #include <drivers/PCI.h> 18 19 #include <util/list.h> 20 21 #include <net_stack.h> 22 23 #include <compat/sys/kernel.h> 24 #include <compat/net/if.h> 25 #include <compat/net/if_var.h> 26 27 struct ifnet; 28 29 struct device { 30 struct device * parent; 31 char dev_name[128]; 32 33 driver_t *driver; 34 struct list children; 35 36 int32 flags; 37 38 int unit; 39 char nameunit[64]; 40 const char * description; 41 void * softc; 42 void * ivars; 43 44 struct { 45 int (*probe)(device_t dev); 46 int (*attach)(device_t dev); 47 int (*detach)(device_t dev); 48 int (*suspend)(device_t dev); 49 int (*resume)(device_t dev); 50 void (*shutdown)(device_t dev); 51 52 int (*miibus_readreg)(device_t, int, int); 53 int (*miibus_writereg)(device_t, int, int, int); 54 void (*miibus_statchg)(device_t); 55 void (*miibus_linkchg)(device_t); 56 void (*miibus_mediainit)(device_t); 57 } methods; 58 59 struct list_link link; 60 }; 61 62 63 struct network_device { 64 struct device base; 65 66 pci_info pci_info; 67 68 int32 open; 69 70 struct ifqueue receive_queue; 71 sem_id receive_sem; 72 73 sem_id link_state_sem; 74 75 struct ifnet * ifp; 76 }; 77 78 79 #define DEVNET(dev) ((device_t)(&(dev)->base)) 80 #define NETDEV(base) ((struct network_device *)(base)) 81 82 83 enum { 84 DEVICE_OPEN = 1 << 0, 85 DEVICE_CLOSED = 1 << 1, 86 DEVICE_NON_BLOCK = 1 << 2, 87 DEVICE_DESC_ALLOCED = 1 << 3, 88 }; 89 90 91 static inline void 92 __unimplemented(const char *method) 93 { 94 char msg[128]; 95 snprintf(msg, sizeof(msg), "fbsd compat, unimplemented: %s", method); 96 panic(msg); 97 } 98 99 100 #define UNIMPLEMENTED() __unimplemented(__FUNCTION__) 101 102 status_t init_mbufs(void); 103 void uninit_mbufs(void); 104 105 status_t init_mutexes(void); 106 void uninit_mutexes(void); 107 108 status_t init_compat_layer(void); 109 110 status_t init_taskqueues(void); 111 void uninit_taskqueues(void); 112 113 /* busdma_machdep.c */ 114 void init_bounce_pages(void); 115 void uninit_bounce_pages(void); 116 117 void driver_printf(const char *format, ...) 118 __attribute__ ((format (__printf__, 1, 2))); 119 void driver_vprintf(const char *format, va_list vl); 120 121 void device_sprintf_name(device_t dev, const char *format, ...) 122 __attribute__ ((format (__printf__, 2, 3))); 123 124 device_t init_device(device_t dev, driver_t *driver); 125 void uninit_device(device_t dev); 126 device_method_signature_t _resolve_method(driver_t *driver, const char *name); 127 128 void ifq_init(struct ifqueue *ifq, const char *name); 129 void ifq_uninit(struct ifqueue *ifq); 130 131 extern struct net_stack_module_info *gStack; 132 extern pci_module_info *gPci; 133 134 extern const char *gDevNameList[]; 135 extern struct network_device *gDevices[]; 136 137 #endif 138