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_OLD "/proc/tty/driver/serial"
16 #define PROC_DRIVER_SERIAL "/proc/tty/driver/serial_8250"
17 #define PROC_DRIVER_MACSERIAL "/proc/tty/driver/macserial"
18 #define PROC_PARPORT_22 "/proc/parport/" /* Final '/' is essential! */
19 #define PROC_PARPORT_24 "/proc/sys/dev/parport/parport"
20 #define PROC_KCORE "/proc/kcore"
21 // #define PROC_USB_DEVICES "/proc/bus/usb/devices"
22 #define PROC_USB_DEVICES "/proc/bus/usb/devices_please-use-sysfs-instead"
23 #define PROC_PROM "/proc/device-tree"
24 #define PROC_MEMINFO "/proc/meminfo"
25 #define PROC_VERSION "/proc/version"
26 #define PROC_ISAPNP "/proc/isapnp"
27 #define PROC_PARTITIONS "/proc/partitions"
28 #define PROC_APM "/proc/apm"
29 #define PROC_XEN_BALLOON "/proc/xen/balloon"
30 
31 #define DEV_NVRAM "/dev/nvram"
32 #define DEV_PSAUX "/dev/psaux"
33 #define DEV_ADBMOUSE "/dev/adbmouse"
34 #define DEV_MEM "/dev/mem"
35 #define DEV_KBD "/dev/kbd"
36 #define DEV_CONSOLE "/dev/console"
37 #define DEV_OPENPROM "/dev/openprom"
38 #define DEV_SUNMOUSE "/dev/sunmouse"
39 #define DEV_MICE "/dev/input/mice"
40 #define DEV_FB "/dev/fb"
41 #define DEV_FB0 "/dev/fb0"
42 
43 #define PROG_MODPROBE "/sbin/modprobe"
44 #define PROG_RMMOD "/sbin/rmmod"
45 #define PROG_CARDCTL "/sbin/cardctl"
46 #define PROG_UDEVINFO "/usr/bin/udevinfo"
47 #define PROG_UDEVADM "/usr/bin/udevadm"
48 
49 #define KLOG_BOOT "/var/log/boot.msg"
50 #define ISAPNP_CONF "/etc/isapnp.conf"
51 
52 #define KERNEL_22 0x020200
53 #define KERNEL_24 0x020400
54 #define KERNEL_26 0x020600
55 
56 #if defined(__s390__) || defined(__s390x__) || defined(__alpha__) || defined(LIBHD_TINY)
57 #define WITH_ISDN 0
58 #else
59 #define WITH_ISDN 1
60 #endif
61 
62 // maximum attribute size in sysfs we expect
63 // (this is to avoid accidentally reading unlimited data)
64 #define MAX_ATTR_SIZE 0x10000
65 
66 #define PROGRESS(a, b, c) progress(hd_data, a, b, c)
67 #define ADD2LOG(a...) hd_log_printf(hd_data, a)
68 
69 /*
70  * define to make (hd_t).unique_id a hex string, otherwise it is a
71  * base64-like string
72  */
73 #undef NUMERIC_UNIQUE_ID
74 
75 /*
76  * exported symbol - all others are not exported by the library
77  */
78 #define API_SYM __attribute__((visibility("default")))
79 
80 /*
81  * All API symbols start with 'hd_' or 'hddb_'.
82  *
83  * Add aliases for some symbols that are widespread throughout libhd sources
84  * to avoid massive code adjustments.
85  */
86 #define read_dir hd_read_dir
87 #define read_file hd_read_file
88 #define name2eisa_id hd_name2eisa_id
89 #define search_str_list hd_search_str_list
90 #define add_str_list hd_add_str_list
91 #define free_str_list hd_free_str_list
92 #define reverse_str_list hd_reverse_str_list
93 #define add_hd_entry hd_add_hd_entry
94 
95 /*
96  * Internal probing module numbers. Use mod_name_by_idx() outside of libhd.
97  */
98 enum mod_idx {
105 };
106 
107 void *new_mem(size_t size);
108 void *resize_mem(void *, size_t);
109 void *add_mem(void *, size_t, size_t);
110 char *new_str(const char *);
111 void *free_mem(void *);
112 int have_common_res(hd_res_t *res1, hd_res_t *res2);
113 void join_res_io(hd_res_t **res1, hd_res_t *res2);
114 void join_res_irq(hd_res_t **res1, hd_res_t *res2);
115 void join_res_dma(hd_res_t **res1, hd_res_t *res2);
117 hd_res_t *add_res_entry(hd_res_t **res, hd_res_t *new_res);
118 hd_t *add_hd_entry(hd_data_t *hd_data, unsigned line, unsigned count);
119 misc_t *free_misc(misc_t *m);
120 scsi_t *free_scsi(scsi_t *scsi, int free_all);
123 void hd_add_id(hd_data_t *hd_data, hd_t *hd);
124 
125 char *isa_id2str(unsigned);
126 char *eisa_vendor_str(unsigned);
127 char *canon_str(char *, int);
128 
129 int hex(char *string, int digits);
130 
131 void hd_log(hd_data_t *hd_data, char *buf, ssize_t len);
132 void hd_log_printf(hd_data_t *hd_data, char *format, ...) __attribute__ ((format (printf, 2, 3)));
133 void hd_log_hex(hd_data_t *hd_data, int with_ascii, unsigned data_len, unsigned char *data);
134 
135 void str_printf(char **buf, int offset, char *format, ...) __attribute__ ((format (printf, 3, 4)));
136 void hexdump(char **buf, int with_ascii, unsigned data_len, unsigned char *data);
137 str_list_t *read_dir_canonical(char *dir_name, int type);
138 str_list_t *subcomponent_list(str_list_t *list, char *comp, int max);
139 int has_subcomponent(str_list_t *list, char *comp);
140 void progress(hd_data_t *hd_data, unsigned pos, unsigned count, char *msg);
141 
144 
146 
147 int str2float(char *s, int n);
148 char *float2str(int i, int n);
149 
150 /* return the file name of a module */
151 char *mod_name_by_idx(unsigned idx);
152 
153 int hd_timeout(void(*func)(void *), void *arg, int timeout);
154 
156 char *get_cmd_param(hd_data_t *hd_data, int field);
157 
158 #ifdef __i386__
159 /* smp/smp.c */
160 int detectSMP(void);
161 #endif
162 
164 int run_cmd(hd_data_t *hd_data, char *cmd);
165 int load_module_with_params(hd_data_t *hd_data, char *module, char *params);
166 int load_module(hd_data_t *hd_data, char *module);
168 int probe_module(hd_data_t *hd_data, char *module);
169 
170 int cmp_hd(hd_t *hd1, hd_t *hd2);
172 
174 
177 
178 unsigned char *read_block0(hd_data_t *hd_data, char *dev, int *timeout);
179 
180 void hd_copy(hd_t *dst, hd_t *src);
181 
182 /* parameter for gather_resources(,,, which) */
183 #define W_IO (1 << 0)
184 #define W_DMA (1 << 1)
185 #define W_IRQ (1 << 2)
186 
187 void gather_resources(misc_t *m, hd_res_t **r, char *name, unsigned which);
188 
189 char *vend_id2str(unsigned vend);
190 
191 int hd_getdisksize(hd_data_t *hd_data, char *dev, int fd, hd_res_t **geo, hd_res_t **size);
192 
193 int is_pnpinfo(ser_device_t *mi, int ofs);
194 
196 
197 void hd_fork(hd_data_t *hd_data, int timeout, int total_timeout);
202 void *hd_shm_add(hd_data_t *hd_data, void *ptr, unsigned len);
203 int hd_is_shm_ptr(hd_data_t *hd_data, void *ptr);
205 
207 
209 hd_t *hd_find_sysfs_id_devname(hd_data_t *hd_data, char *id, char *devname);
210 int hd_attr_uint(char* attr, uint64_t* u, int base);
211 str_list_t *hd_attr_list(char *str);
212 char *hd_sysfs_id(char *path);
213 char *hd_sysfs_name2_dev(char *str);
214 char *hd_sysfs_dev2_name(char *str);
216 char *hd_sysfs_find_driver(hd_data_t *hd_data, char *sysfs_id, int exact);
219 
220 char* get_sysfs_attr(const char* bus, const char* device, const char* attr);
221 char *get_sysfs_attr_by_path(const char *path, const char *attr);
222 char *get_sysfs_attr_by_path2(const char *path, const char *attr, unsigned *len);
223 
224 void hd_pci_complete_data(hd_t *hd);
226 
228 char *hd_hal_print_prop(hal_prop_t *prop);
229 
230 void hal_invalidate(hal_prop_t *prop);
231 void hal_invalidate_all(hal_prop_t *prop, const char *key);
232 hal_prop_t *hal_get_any(hal_prop_t *prop, const char *key);
233 hal_prop_t *hal_get_bool(hal_prop_t *prop, const char *key);
234 hal_prop_t *hal_get_int32(hal_prop_t *prop, const char *key);
235 hal_prop_t *hal_get_str(hal_prop_t *prop, const char *key);
236 hal_prop_t *hal_get_list(hal_prop_t *prop, const char *key);
237 char *hal_get_useful_str(hal_prop_t *prop, const char *key);
238 
241 
242 char *hd_get_hddb_dir(void);
243 char *hd_get_hddb_path(char *sub);
244 
245 int hd_mod_cmp(char *str1, char *str2);
246 
250 
251 str_list_t *sort_str_list(str_list_t *sl0, int (*cmp_func)(const void *, const void *));
252 
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
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:4377
char * eisa_vendor_str(unsigned)
Definition: hd.c:2181
Definition: hd_int.h:99
void * free_mem(void *)
Definition: hd.c:1614
Definition: hd_int.h:103
mod_idx
Definition: hd_int.h:98
Definition: hd_int.h:100
str_list_t * get_cmdline(hd_data_t *hd_data, char *key)
Definition: hd.c:3665
void remove_hd_entries(hd_data_t *hd_data)
Definition: hd.c:2807
int hd_getdisksize(hd_data_t *hd_data, char *dev, int fd, hd_res_t **geo, hd_res_t **size)
Definition: hd.c:5093
char * get_cmd_param(hd_data_t *hd_data, int field)
Definition: hd.c:3720
Definition: hd_int.h:101
scsi_t * free_scsi(scsi_t *scsi, int free_all)
Definition: hd.c:1492
char * hd_sysfs_find_driver(hd_data_t *hd_data, char *sysfs_id, int exact)
Definition: block.c:428
Definition: hd_int.h:101
char * new_str(const char *)
Definition: hd.c:1597
int run_cmd(hd_data_t *hd_data, char *cmd)
Definition: hd.c:3889
Definition: hd_int.h:99
Definition: hd_int.h:101
str_list_t * read_kmods(hd_data_t *hd_data)
Definition: hd.c:3640
Definition: hd_int.h:102
Definition: hd_int.h:102
Definition: hd_int.h:101
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:1571
Definition: hd_int.h:100
misc_t * free_misc(misc_t *m)
Definition: hd.c:1459
char * canon_str(char *, int)
Definition: hd.c:2218
int detect_smp_bios(hd_data_t *hd_data)
Definition: hd_int.h:104
int hex(char *string, int digits)
Definition: hd.c:2246
int type
Definition: hd.h:1160
Definition: hd_int.h:101
void join_res_irq(hd_res_t **res1, hd_res_t *res2)
Definition: hd.c:1669
hd_t * hd_find_sysfs_id(hd_data_t *hd_data, char *id)
Definition: hd.c:5814
libhd resource union
Definition: hd.h:1864
Definition: hd_int.h:103
HAL device.
Definition: hd.h:1654
Definition: hd.h:2184
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:6176
int str2float(char *s, int n)
Definition: hd.c:2260
str_list_t * hd_module_list(hd_data_t *hd_data, unsigned id)
Definition: hd.c:6025
hal_prop_t * hal_add_new(hal_prop_t **prop)
Definition: hal.c:348
Individual hardware item.
Definition: hd.h:2239
void join_res_dma(hd_res_t **res1, hd_res_t *res2)
Definition: hd.c:1689
Definition: hd_int.h:99
str_list_t * read_dir_canonical(char *dir_name, int type)
Definition: hd.c:2664
hd_detail_t * free_hd_detail(hd_detail_t *d)
Definition: hd.c:1228
char * get_sysfs_attr_by_path2(const char *path, const char *attr, unsigned *len)
Definition: hd.c:6252
Definition: isdn_cdb_def.h:22
void hd_fork_done(hd_data_t *hd_data)
Definition: hd.c:5462
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:6313
unsigned has_something_attached(hd_data_t *hd_data, hd_t *hd)
Definition: hd.c:4196
String list type.
Definition: hd.h:411
Definition: hd_int.h:103
int unload_module(hd_data_t *hd_data, char *module)
Definition: hd.c:3953
void hd_copy(hd_t *dst, hd_t *src)
Definition: hd.c:3283
int load_module(hd_data_t *hd_data, char *module)
Definition: hd.c:3948
Definition: hd_int.h:104
int hd_report_this(hd_data_t *hd_data, hd_t *hd)
Definition: hd.c:6015
char * float2str(int i, int n)
Definition: hd.c:2291
char * hd_get_hddb_dir(void)
Definition: hd.c:6121
Definition: hd_int.h:103
void join_res_io(hd_res_t **res1, hd_res_t *res2)
Definition: hd.c:1621
Definition: hd_int.h:103
int get_probe_val_int(hd_data_t *hd_data, enum probe_feature feature)
Definition: hd.c:396
Definition: hd_int.h:104
str_list_t * subcomponent_list(str_list_t *list, char *comp, int max)
Definition: hd.c:2707
hal_prop_t * hal_get_int32(hal_prop_t *prop, const char *key)
Definition: hal.c:299
Definition: hd_int.h:103
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:411
void hd_add_id(hd_data_t *hd_data, hd_t *hd)
Definition: hd.c:4308
hal_prop_t * hal_get_any(hal_prop_t *prop, const char *key)
Definition: hal.c:279
Serial device configuration information.
Definition: hd.h:1937
raw SCSI data
Definition: hd.h:1148
int hd_attr_uint(char *attr, uint64_t *u, int base)
Definition: hd.c:6145
Definition: hd_int.h:102
void hd_move_to_shm(hd_data_t *hd_data)
Definition: hd.c:5651
Definition: hd.h:2084
int hd_is_shm_ptr(hd_data_t *hd_data, void *ptr)
Definition: hd.c:5617
char * hd_sysfs_dev2_name(char *str)
Definition: hd.c:6209
char * hd_sysfs_name2_dev(char *str)
Definition: hd.c:6188
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:6293
hal_device_t * hd_free_hal_devices(hal_device_t *dev)
Definition: hd.c:1103
void void hexdump(char **buf, int with_ascii, unsigned data_len, unsigned char *data)
Definition: hd.c:2467
Definition: hd_int.h:104
int load_module_with_params(hd_data_t *hd_data, char *module, char *params)
Definition: hd.c:3929
str_list_t * get_probe_val_list(hd_data_t *hd_data, enum probe_feature feature)
Definition: hd.c:426
void hd_shm_init(hd_data_t *hd_data)
Definition: hd.c:5518
driver_info_t * free_driver_info(driver_info_t *di)
Definition: hd.c:1122
int probe_module(hd_data_t *hd_data, char *module)
Definition: hd.c:3910
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:5365
void gather_resources(misc_t *m, hd_res_t **r, char *name, unsigned which)
Definition: misc.c:603
Definition: hd_int.h:100
void * hd_shm_add(hd_data_t *hd_data, void *ptr, unsigned len)
Definition: hd.c:5593
Definition: hd_int.h:104
void hd_pci_read_data(hd_data_t *hd_data)
Definition: pci.c:153
Definition: hd_int.h:100
Definition: hd_int.h:102
str_list_t * hd_attr_list(char *str)
Definition: hd.c:6163
Definition: hd_int.h:104
char * hd_get_hddb_path(char *sub)
Definition: hd.c:6132
static hd_data_t * hd_data
Definition: pppoe.c:30
void remove_tagged_hd_entries(hd_data_t *hd_data)
Definition: hd.c:2825
Definition: hd_int.h:101
void update_irq_usage(hd_data_t *hd_data)
Definition: hd.c:3862
Definition: hd_int.h:101
int detect_smp_prom(hd_data_t *hd_data)
PROM tree on PPC.
Definition: hd.h:1185
HAL device properties.
Definition: hd.h:1636
Definition: hd.h:1914
hd_res_t * free_res_list(hd_res_t *res)
Definition: hd.c:1746
Definition: hd_int.h:102
void hd_shm_clean(hd_data_t *hd_data)
Definition: hd.c:5558
#define add_hd_entry
Definition: hd_int.h:93
void read_udevinfo(hd_data_t *hd_data)
Definition: hd.c:5717
int cmp_hd(hd_t *hd1, hd_t *hd2)
Definition: hd.c:3972
int hd_timeout(void(*func)(void *), void *arg, int timeout)
Definition: hd.c:3587
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:2748
hd_t * hd_find_sysfs_id_devname(hd_data_t *hd_data, char *id, char *devname)
Definition: hd.c:5828
void hd_log(hd_data_t *hd_data, char *buf, ssize_t len)
Definition: hd.c:2362
char * vend_id2str(unsigned vend)
Definition: hd.c:4502
void hd_pci_complete_data(hd_t *hd)
Definition: pci.c:491
Definition: hd_int.h:99
char * mod_name_by_idx(unsigned idx)
Definition: hd.c:2351
Definition: hd_int.h:99
Definition: hd_int.h:100
hd_res_t * add_res_entry(hd_res_t **res, hd_res_t *new_res)
Definition: hd.c:1796
void * add_mem(void *, size_t, size_t)
Definition: hd.c:1583
Definition: hd_int.h:100
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:4421
Definition: hd_int.h:102
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:5867
void hd_shm_done(hd_data_t *hd_data)
Definition: hd.c:5580
Definition: isdn_cdb_def.h:25
char * isa_id2str(unsigned)
Definition: hd.c:2166
char * get_sysfs_attr(const char *bus, const char *device, const char *attr)
Definition: hd.c:6227
Definition: hd_int.h:104
uint64_t size
Definition: hd.h:1167
char * get_sysfs_attr_by_path(const char *path, const char *attr)
Definition: hd.c:6243
Definition: hd_int.h:100
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:1712
int has_subcomponent(str_list_t *list, char *comp)
Definition: hd.c:2734
void * new_mem(size_t size)
Definition: hd.c:1555
void void hd_log_hex(hd_data_t *hd_data, int with_ascii, unsigned data_len, unsigned char *data)
Definition: hd.c:2404
Holds all data accumulated during hardware probing.
Definition: hd.h:2647
int is_pcmcia_ctrl(hd_data_t *hd_data, hd_t *hd)
Definition: hd.c:5263
Definition: hd_int.h:102
Definition: hd_int.h:99