libhd  5.0
hd_int.h
Go to the documentation of this file.
1 #define PROC_CMDLINE "/proc/cmdline"
2 #define PROC_PCI_DEVICES "/proc/bus/pci/devices"
3 #define PROC_PCI_BUS "/proc/bus/pci"
4 #define PROC_CPUINFO "/proc/cpuinfo"
5 #define PROC_IOPORTS "/proc/ioports"
6 #define PROC_DMA "/proc/dma"
7 #define PROC_INTERRUPTS "/proc/interrupts"
8 #define PROC_NVRAM_22 "/proc/driver/nvram"
9 #define PROC_NVRAM_24 "/proc/nvram"
10 #define PROC_IDE "/proc/ide"
11 #define PROC_SCSI "/proc/scsi"
12 #define PROC_CDROM_INFO "/proc/sys/dev/cdrom/info"
13 #define PROC_NET_IF_INFO "/proc/net/dev"
14 #define PROC_MODULES "/proc/modules"
15 #define PROC_DRIVER_SERIAL "/proc/tty/driver/serial"
16 #define PROC_DRIVER_MACSERIAL "/proc/tty/driver/macserial"
17 #define PROC_PARPORT_22 "/proc/parport/" /* Final '/' is essential! */
18 #define PROC_PARPORT_24 "/proc/sys/dev/parport/parport"
19 #define PROC_KCORE "/proc/kcore"
20 // #define PROC_USB_DEVICES "/proc/bus/usb/devices"
21 #define PROC_USB_DEVICES "/proc/bus/usb/devices_please-use-sysfs-instead"
22 #define PROC_PROM "/proc/device-tree"
23 #define PROC_MEMINFO "/proc/meminfo"
24 #define PROC_VERSION "/proc/version"
25 #define PROC_ISAPNP "/proc/isapnp"
26 #define PROC_PARTITIONS "/proc/partitions"
27 #define PROC_APM "/proc/apm"
28 #define PROC_XEN_BALLOON "/proc/xen/balloon"
29 
30 #define DEV_NVRAM "/dev/nvram"
31 #define DEV_PSAUX "/dev/psaux"
32 #define DEV_ADBMOUSE "/dev/adbmouse"
33 #define DEV_MEM "/dev/mem"
34 #define DEV_KBD "/dev/kbd"
35 #define DEV_CONSOLE "/dev/console"
36 #define DEV_OPENPROM "/dev/openprom"
37 #define DEV_SUNMOUSE "/dev/sunmouse"
38 #define DEV_MICE "/dev/input/mice"
39 #define DEV_FB "/dev/fb"
40 #define DEV_FB0 "/dev/fb0"
41 
42 #define PROG_MODPROBE "/sbin/modprobe"
43 #define PROG_RMMOD "/sbin/rmmod"
44 #define PROG_CARDCTL "/sbin/cardctl"
45 #define PROG_UDEVINFO "/usr/bin/udevinfo"
46 #define PROG_UDEVADM "/bin/udevadm"
47 
48 #define KLOG_BOOT "/var/log/boot.msg"
49 #define ISAPNP_CONF "/etc/isapnp.conf"
50 
51 #define KERNEL_22 0x020200
52 #define KERNEL_24 0x020400
53 #define KERNEL_26 0x020600
54 
55 #if defined(__s390__) || defined(__s390x__) || defined(__alpha__) || defined(LIBHD_TINY)
56 #define WITH_ISDN 0
57 #else
58 #define WITH_ISDN 1
59 #endif
60 
61 // maximum attribute size in sysfs we expect
62 // (this is to avoid accidentally reading unlimited data)
63 #define MAX_ATTR_SIZE 0x10000
64 
65 #define PROGRESS(a, b, c) progress(hd_data, a, b, c)
66 #define ADD2LOG(a...) hd_log_printf(hd_data, a)
67 
68 /*
69  * define to make (hd_t).unique_id a hex string, otherwise it is a
70  * base64-like string
71  */
72 #undef NUMERIC_UNIQUE_ID
73 
74 /*
75  * Internal probing module numbers. Use mod_name_by_idx() outside of libhd.
76  */
77 enum mod_idx {
84 };
85 
86 void *new_mem(size_t size);
87 void *resize_mem(void *, size_t);
88 void *add_mem(void *, size_t, size_t);
89 char *new_str(const char *);
90 void *free_mem(void *);
91 int have_common_res(hd_res_t *res1, hd_res_t *res2);
92 void join_res_io(hd_res_t **res1, hd_res_t *res2);
93 void join_res_irq(hd_res_t **res1, hd_res_t *res2);
94 void join_res_dma(hd_res_t **res1, hd_res_t *res2);
96 hd_res_t *add_res_entry(hd_res_t **res, hd_res_t *new_res);
97 hd_t *add_hd_entry(hd_data_t *hd_data, unsigned line, unsigned count);
99 scsi_t *free_scsi(scsi_t *scsi, int free_all);
102 void hd_add_id(hd_data_t *hd_data, hd_t *hd);
103 
104 char *isa_id2str(unsigned);
105 char *eisa_vendor_str(unsigned);
106 unsigned name2eisa_id(char *);
107 char *canon_str(char *, int);
108 
109 int hex(char *string, int digits);
110 
111 void hd_log(hd_data_t *hd_data, char *buf, ssize_t len);
112 void hd_log_printf(hd_data_t *hd_data, char *format, ...) __attribute__ ((format (printf, 2, 3)));
113 void hd_log_hex(hd_data_t *hd_data, int with_ascii, unsigned data_len, unsigned char *data);
114 
115 void str_printf(char **buf, int offset, char *format, ...) __attribute__ ((format (printf, 3, 4)));
116 void hexdump(char **buf, int with_ascii, unsigned data_len, unsigned char *data);
117 str_list_t *search_str_list(str_list_t *sl, char *str);
118 str_list_t *add_str_list(str_list_t **sl, char *str);
121 str_list_t *read_file(char *file_name, unsigned start_line, unsigned lines);
122 str_list_t *read_dir(char *dir_name, int type);
123 char *hd_read_sysfs_link(char *base_dir, char *link_name);
124 void progress(hd_data_t *hd_data, unsigned pos, unsigned count, char *msg);
125 
126 void remove_hd_entries(hd_data_t *hd_data);
127 void remove_tagged_hd_entries(hd_data_t *hd_data);
128 
130 
131 int str2float(char *s, int n);
132 char *float2str(int i, int n);
133 
134 /* return the file name of a module */
135 char *mod_name_by_idx(unsigned idx);
136 
137 int hd_timeout(void(*func)(void *), void *arg, int timeout);
138 
139 str_list_t *read_kmods(hd_data_t *hd_data);
140 char *get_cmd_param(hd_data_t *hd_data, int field);
141 
142 #ifdef __i386__
143 /* smp/smp.c */
144 int detectSMP(void);
145 #endif
146 
147 void update_irq_usage(hd_data_t *hd_data);
148 int run_cmd(hd_data_t *hd_data, char *cmd);
149 int load_module_with_params(hd_data_t *hd_data, char *module, char *params);
150 int load_module(hd_data_t *hd_data, char *module);
151 int unload_module(hd_data_t *hd_data, char *module);
152 int probe_module(hd_data_t *hd_data, char *module);
153 
154 int cmp_hd(hd_t *hd1, hd_t *hd2);
155 unsigned has_something_attached(hd_data_t *hd_data, hd_t *hd);
156 
157 str_list_t *get_cmdline(hd_data_t *hd_data, char *key);
158 
159 int detect_smp_bios(hd_data_t *hd_data);
160 int detect_smp_prom(hd_data_t *hd_data);
161 
162 unsigned char *read_block0(hd_data_t *hd_data, char *dev, int *timeout);
163 
164 void hd_copy(hd_t *dst, hd_t *src);
165 
166 /* parameter for gather_resources(,,, which) */
167 #define W_IO (1 << 0)
168 #define W_DMA (1 << 1)
169 #define W_IRQ (1 << 2)
170 
171 void gather_resources(misc_t *m, hd_res_t **r, char *name, unsigned which);
172 
173 char *vend_id2str(unsigned vend);
174 
175 int hd_getdisksize(hd_data_t *hd_data, char *dev, int fd, hd_res_t **geo, hd_res_t **size);
176 
177 str_list_t *hd_split(char del, const char *str);
178 char *hd_join(char *del, str_list_t *str);
179 
180 int is_pnpinfo(ser_device_t *mi, int ofs);
181 
182 int is_pcmcia_ctrl(hd_data_t *hd_data, hd_t *hd);
183 
184 void hd_fork(hd_data_t *hd_data, int timeout, int total_timeout);
185 void hd_fork_done(hd_data_t *hd_data);
186 void hd_shm_init(hd_data_t *hd_data);
187 void hd_shm_clean(hd_data_t *hd_data);
188 void hd_shm_done(hd_data_t *hd_data);
189 void *hd_shm_add(hd_data_t *hd_data, void *ptr, unsigned len);
190 int hd_is_shm_ptr(hd_data_t *hd_data, void *ptr);
191 void hd_move_to_shm(hd_data_t *hd_data);
192 
193 void read_udevinfo(hd_data_t *hd_data);
194 
195 hd_t *hd_find_sysfs_id(hd_data_t *hd_data, char *id);
196 hd_t *hd_find_sysfs_id_devname(hd_data_t *hd_data, char *id, char *devname);
197 int hd_attr_uint(char* attr, uint64_t* u, int base);
198 str_list_t *hd_attr_list(char *str);
199 char *hd_sysfs_id(char *path);
200 char *hd_sysfs_name2_dev(char *str);
201 char *hd_sysfs_dev2_name(char *str);
202 void hd_sysfs_driver_list(hd_data_t *hd_data);
203 char *hd_sysfs_find_driver(hd_data_t *hd_data, char *sysfs_id, int exact);
204 int hd_report_this(hd_data_t *hd_data, hd_t *hd);
205 str_list_t *hd_module_list(hd_data_t *hd_data, unsigned id);
206 
207 char* get_sysfs_attr(const char* bus, const char* device, const char* attr);
208 char *get_sysfs_attr_by_path(const char *path, const char *attr);
209 char *get_sysfs_attr_by_path2(const char *path, const char *attr, unsigned *len);
210 
211 void hd_pci_complete_data(hd_t *hd);
212 void hd_pci_read_data(hd_data_t *hd_data);
213 
215 char *hd_hal_print_prop(hal_prop_t *prop);
216 
217 void hal_invalidate(hal_prop_t *prop);
218 void hal_invalidate_all(hal_prop_t *prop, const char *key);
219 hal_prop_t *hal_get_any(hal_prop_t *prop, const char *key);
220 hal_prop_t *hal_get_bool(hal_prop_t *prop, const char *key);
221 hal_prop_t *hal_get_int32(hal_prop_t *prop, const char *key);
222 hal_prop_t *hal_get_str(hal_prop_t *prop, const char *key);
223 hal_prop_t *hal_get_list(hal_prop_t *prop, const char *key);
224 char *hal_get_useful_str(hal_prop_t *prop, const char *key);
225 
226 hal_device_t *hal_find_device(hd_data_t *hd_data, char *udi);
228 
229 char *hd_get_hddb_dir(void);
230 char *hd_get_hddb_path(char *sub);
231 
232 int hd_mod_cmp(char *str1, char *str2);
233 
235 char *get_probe_val_str(hd_data_t *hd_data, enum probe_feature feature);
237 
238 str_list_t *sort_str_list(str_list_t *sl0, int (*cmp_func)(const void *, const void *));
239 
240 
241 #ifdef __cplusplus
242 }
243 #endif
hal_prop_t * hal_get_bool(hal_prop_t *prop, const char *key)
Definition: hal.c:289
devtree_t * free_devtree(hd_data_t *hd_data)
Definition: hd.c:4307
char * eisa_vendor_str(unsigned)
Definition: hd.c:2171
Definition: hd_int.h:78
void * free_mem(void *)
Definition: hd.c:1611
Definition: hd_int.h:82
mod_idx
Definition: hd_int.h:77
Definition: hd_int.h:79
str_list_t * get_cmdline(hd_data_t *hd_data, char *key)
Definition: hd.c:3595
void remove_hd_entries(hd_data_t *hd_data)
Definition: hd.c:2728
int hd_getdisksize(hd_data_t *hd_data, char *dev, int fd, hd_res_t **geo, hd_res_t **size)
Definition: hd.c:5019
char * get_cmd_param(hd_data_t *hd_data, int field)
Definition: hd.c:3650
Definition: hd_int.h:80
scsi_t * free_scsi(scsi_t *scsi, int free_all)
Definition: hd.c:1489
char * hd_sysfs_find_driver(hd_data_t *hd_data, char *sysfs_id, int exact)
Definition: block.c:388
Definition: hd_int.h:80
char * new_str(const char *)
Definition: hd.c:1594
str_list_t * read_dir(char *dir_name, int type)
Definition: hd.c:2593
int run_cmd(hd_data_t *hd_data, char *cmd)
Definition: hd.c:3819
Definition: hd_int.h:78
Definition: hd_int.h:80
str_list_t * read_kmods(hd_data_t *hd_data)
Definition: hd.c:3570
str_list_t * search_str_list(str_list_t *sl, char *str)
Definition: hd.c:2481
Definition: hd_int.h:81
Definition: hd_int.h:81
Definition: hd_int.h:80
hal_prop_t * hal_get_list(hal_prop_t *prop, const char *key)
Definition: hal.c:338
void * resize_mem(void *, size_t)
Definition: hd.c:1568
Definition: hd_int.h:79
misc_t * free_misc(misc_t *m)
Definition: hd.c:1456
char * canon_str(char *, int)
Definition: hd.c:2208
int detect_smp_bios(hd_data_t *hd_data)
Definition: hd_int.h:83
str_list_t * hd_split(char del, const char *str)
Definition: hd.c:5139
int hex(char *string, int digits)
Definition: hd.c:2236
int type
Definition: hd.h:1156
Definition: hd_int.h:80
void join_res_irq(hd_res_t **res1, hd_res_t *res2)
Definition: hd.c:1666
hd_t * hd_find_sysfs_id(hd_data_t *hd_data, char *id)
Definition: hd.c:5740
libhd resource union
Definition: hd.h:1827
Definition: hd_int.h:82
HAL device.
Definition: hd.h:1629
Definition: hd.h:2146
void hal_invalidate(hal_prop_t *prop)
Definition: hal.c:262
hal_device_t * hal_find_device(hd_data_t *hd_data, char *udi)
Definition: hal.c:248
char * hd_sysfs_id(char *path)
Definition: hd.c:6031
int str2float(char *s, int n)
Definition: hd.c:2250
str_list_t * hd_module_list(hd_data_t *hd_data, unsigned id)
Definition: hd.c:5880
hal_prop_t * hal_add_new(hal_prop_t **prop)
Definition: hal.c:348
Individual hardware item.
Definition: hd.h:2201
void join_res_dma(hd_res_t **res1, hd_res_t *res2)
Definition: hd.c:1686
Definition: hd_int.h:78
unsigned name2eisa_id(char *)
Definition: hd.c:2187
hd_detail_t * free_hd_detail(hd_detail_t *d)
Definition: hd.c:1230
char * get_sysfs_attr_by_path2(const char *path, const char *attr, unsigned *len)
Definition: hd.c:6107
Definition: isdn_cdb_def.h:22
void hd_fork_done(hd_data_t *hd_data)
Definition: hd.c:5388
char * hal_get_useful_str(hal_prop_t *prop, const char *key)
Definition: hal.c:319
str_list_t * sort_str_list(str_list_t *sl0, int(*cmp_func)(const void *, const void *))
Definition: hd.c:6168
unsigned has_something_attached(hd_data_t *hd_data, hd_t *hd)
Definition: hd.c:4126
String list type.
Definition: hd.h:410
Definition: hd_int.h:82
int unload_module(hd_data_t *hd_data, char *module)
Definition: hd.c:3883
void hd_copy(hd_t *dst, hd_t *src)
Definition: hd.c:3213
int load_module(hd_data_t *hd_data, char *module)
Definition: hd.c:3878
Definition: hd_int.h:83
int hd_report_this(hd_data_t *hd_data, hd_t *hd)
Definition: hd.c:5870
str_list_t * free_str_list(str_list_t *list)
Definition: hd.c:2510
char * float2str(int i, int n)
Definition: hd.c:2281
hd_t * add_hd_entry(hd_data_t *hd_data, unsigned line, unsigned count)
Definition: hd.c:1794
char * hd_get_hddb_dir(void)
Definition: hd.c:5976
Definition: hd_int.h:82
void join_res_io(hd_res_t **res1, hd_res_t *res2)
Definition: hd.c:1618
Definition: hd_int.h:82
int get_probe_val_int(hd_data_t *hd_data, enum probe_feature feature)
Definition: hd.c:402
Definition: hd_int.h:83
hal_prop_t * hal_get_int32(hal_prop_t *prop, const char *key)
Definition: hal.c:299
Definition: hd_int.h:82
probe_feature
flags to control the probing.
Definition: hd.h:112
char * get_probe_val_str(hd_data_t *hd_data, enum probe_feature feature)
Definition: hd.c:417
void hd_add_id(hd_data_t *hd_data, hd_t *hd)
Definition: hd.c:4238
hal_prop_t * hal_get_any(hal_prop_t *prop, const char *key)
Definition: hal.c:279
Serial device configuration information.
Definition: hd.h:1899
raw SCSI data
Definition: hd.h:1144
int hd_attr_uint(char *attr, uint64_t *u, int base)
Definition: hd.c:6000
Definition: hd_int.h:81
void hd_move_to_shm(hd_data_t *hd_data)
Definition: hd.c:5577
Definition: hd.h:2046
int hd_is_shm_ptr(hd_data_t *hd_data, void *ptr)
Definition: hd.c:5543
char * hd_sysfs_dev2_name(char *str)
Definition: hd.c:6064
char * hd_sysfs_name2_dev(char *str)
Definition: hd.c:6043
hal_prop_t * hal_get_str(hal_prop_t *prop, const char *key)
Definition: hal.c:309
int hd_mod_cmp(char *str1, char *str2)
Definition: hd.c:6148
hal_device_t * hd_free_hal_devices(hal_device_t *dev)
Definition: hd.c:1105
void void hexdump(char **buf, int with_ascii, unsigned data_len, unsigned char *data)
Definition: hd.c:2457
Definition: hd_int.h:83
int load_module_with_params(hd_data_t *hd_data, char *module, char *params)
Definition: hd.c:3859
str_list_t * get_probe_val_list(hd_data_t *hd_data, enum probe_feature feature)
Definition: hd.c:432
void hd_shm_init(hd_data_t *hd_data)
Definition: hd.c:5444
driver_info_t * free_driver_info(driver_info_t *di)
Definition: hd.c:1124
int probe_module(hd_data_t *hd_data, char *module)
Definition: hd.c:3840
Definition: isdn_cdb_def.h:6
static char line[1024]
Definition: cdbisdn.c:29
void hd_fork(hd_data_t *hd_data, int timeout, int total_timeout)
Definition: hd.c:5291
void gather_resources(misc_t *m, hd_res_t **r, char *name, unsigned which)
Definition: misc.c:603
Definition: hd_int.h:79
void * hd_shm_add(hd_data_t *hd_data, void *ptr, unsigned len)
Definition: hd.c:5519
Definition: hd_int.h:83
void hd_pci_read_data(hd_data_t *hd_data)
Definition: pci.c:144
Definition: hd_int.h:79
Definition: hd_int.h:81
str_list_t * hd_attr_list(char *str)
Definition: hd.c:6018
Definition: hd_int.h:83
char * hd_get_hddb_path(char *sub)
Definition: hd.c:5987
static hd_data_t * hd_data
Definition: pppoe.c:29
void remove_tagged_hd_entries(hd_data_t *hd_data)
Definition: hd.c:2746
Definition: hd_int.h:80
void update_irq_usage(hd_data_t *hd_data)
Definition: hd.c:3792
Definition: hd_int.h:80
int detect_smp_prom(hd_data_t *hd_data)
char * hd_join(char *del, str_list_t *str)
Definition: hd.c:5158
PROM tree on PPC.
Definition: hd.h:1181
HAL device properties.
Definition: hd.h:1611
Definition: hd.h:1876
hd_res_t * free_res_list(hd_res_t *res)
Definition: hd.c:1743
Definition: hd_int.h:81
void hd_shm_clean(hd_data_t *hd_data)
Definition: hd.c:5484
char * hd_read_sysfs_link(char *base_dir, char *link_name)
Definition: hd.c:2648
str_list_t * reverse_str_list(str_list_t *list)
Definition: hd.c:2525
void read_udevinfo(hd_data_t *hd_data)
Definition: hd.c:5643
int cmp_hd(hd_t *hd1, hd_t *hd2)
Definition: hd.c:3902
int hd_timeout(void(*func)(void *), void *arg, int timeout)
Definition: hd.c:3517
void hal_invalidate_all(hal_prop_t *prop, const char *key)
Definition: hal.c:271
void str_printf(char **buf, int offset, char *format,...) __attribute__((format(printf
void progress(hd_data_t *hd_data, unsigned pos, unsigned count, char *msg)
Definition: hd.c:2669
hd_t * hd_find_sysfs_id_devname(hd_data_t *hd_data, char *id, char *devname)
Definition: hd.c:5754
str_list_t * add_str_list(str_list_t **sl, char *str)
Definition: hd.c:2496
void hd_log(hd_data_t *hd_data, char *buf, ssize_t len)
Definition: hd.c:2352
char * vend_id2str(unsigned vend)
Definition: hd.c:4432
void hd_pci_complete_data(hd_t *hd)
Definition: pci.c:479
Definition: hd_int.h:78
char * mod_name_by_idx(unsigned idx)
Definition: hd.c:2341
Definition: hd_int.h:78
Definition: hd_int.h:79
hd_res_t * add_res_entry(hd_res_t **res, hd_res_t *new_res)
Definition: hd.c:1786
void * add_mem(void *, size_t, size_t)
Definition: hd.c:1580
Definition: hd_int.h:79
char * hd_hal_print_prop(hal_prop_t *prop)
Definition: hal.c:439
unsigned char * read_block0(hd_data_t *hd_data, char *dev, int *timeout)
Definition: hd.c:4351
Definition: hd_int.h:81
void hd_log_printf(hd_data_t *hd_data, char *format,...) __attribute__((format(printf
void hd_sysfs_driver_list(hd_data_t *hd_data)
Definition: hd.c:5796
void hd_shm_done(hd_data_t *hd_data)
Definition: hd.c:5506
Definition: isdn_cdb_def.h:25
char * isa_id2str(unsigned)
Definition: hd.c:2156
char * get_sysfs_attr(const char *bus, const char *device, const char *attr)
Definition: hd.c:6082
Definition: hd_int.h:83
uint64_t size
Definition: hd.h:1163
char * get_sysfs_attr_by_path(const char *path, const char *attr)
Definition: hd.c:6098
Definition: hd_int.h:79
int is_pnpinfo(ser_device_t *mi, int ofs)
Definition: modem.c:852
int have_common_res(hd_res_t *res1, hd_res_t *res2)
Definition: hd.c:1709
str_list_t * read_file(char *file_name, unsigned start_line, unsigned lines)
Definition: hd.c:2544
void * new_mem(size_t size)
Definition: hd.c:1552
void void hd_log_hex(hd_data_t *hd_data, int with_ascii, unsigned data_len, unsigned char *data)
Definition: hd.c:2394
Holds all data accumulated during hardware probing.
Definition: hd.h:2609
int is_pcmcia_ctrl(hd_data_t *hd_data, hd_t *hd)
Definition: hd.c:5189
Definition: hd_int.h:81
Definition: hd_int.h:78