2023-11-07 22:31:24 +03:00
|
|
|
#include <system.h>
|
2023-11-26 18:23:58 +03:00
|
|
|
|
2023-11-07 22:31:24 +03:00
|
|
|
typedef struct {
|
|
|
|
char *name;
|
|
|
|
uint16_t id;
|
|
|
|
} vendor_t;
|
2023-11-26 13:12:57 +03:00
|
|
|
|
2023-11-26 18:23:58 +03:00
|
|
|
static vendor_t **parse_file(char *str, uint64_t num_vendors, uint64_t size) {
|
2023-12-12 21:11:06 +03:00
|
|
|
vendor_t **vendor_list = (vendor_t **)alloc(num_vendors * sizeof(vendor_t *));
|
2023-11-26 18:23:58 +03:00
|
|
|
|
2023-11-26 13:12:57 +03:00
|
|
|
if (vendor_list == NULL) { return NULL; }
|
2023-12-12 21:11:06 +03:00
|
|
|
for (uint64_t i = 0; i < num_vendors; i++) { vendor_list[i] = (vendor_t *)alloc(sizeof(vendor_t)); }
|
2023-11-26 13:12:57 +03:00
|
|
|
|
|
|
|
uint64_t i = 0;
|
2023-11-26 18:23:58 +03:00
|
|
|
|
|
|
|
char *line = alloc(strlen(str) + 1);
|
|
|
|
char *temp = alloc(strlen(str) + 1);
|
|
|
|
|
|
|
|
if (line == NULL) { return NULL; }
|
|
|
|
if (temp == NULL) { return NULL; }
|
|
|
|
strcpy(line, str);
|
|
|
|
|
2023-11-26 13:12:57 +03:00
|
|
|
while (line != NULL && i < num_vendors) {
|
2023-11-26 18:23:58 +03:00
|
|
|
temp = realloc(temp, strlen(line) + 1);
|
|
|
|
strcpy(temp, line);
|
|
|
|
|
|
|
|
char *name = trstr(temp, ';');
|
|
|
|
char *id_str = strtok(temp, ";");
|
|
|
|
|
2023-11-26 13:12:57 +03:00
|
|
|
name = strtok(name, "\n");
|
2023-11-26 18:23:58 +03:00
|
|
|
name[strlen(name) - 1] = '\0';
|
2023-11-26 13:12:57 +03:00
|
|
|
|
|
|
|
if (id_str != NULL && name != NULL) {
|
2023-11-26 18:23:58 +03:00
|
|
|
vendor_list[i]->id = strtol(id_str, NULL, 16);
|
|
|
|
vendor_list[i]->name = name;
|
2023-11-26 13:12:57 +03:00
|
|
|
i++;
|
|
|
|
}
|
2023-11-26 18:23:58 +03:00
|
|
|
temp = trstr(line, '\n');
|
|
|
|
strcpy(line, temp);
|
2023-11-26 13:12:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i != num_vendors) {
|
2023-11-26 18:23:58 +03:00
|
|
|
for (uint64_t j = 0; j < i; j++) { free(vendor_list[j]->name); }
|
2023-11-26 13:12:57 +03:00
|
|
|
free(vendor_list);
|
2023-11-26 18:23:58 +03:00
|
|
|
free(line);
|
|
|
|
free(temp);
|
2023-11-26 13:12:57 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-11-26 18:23:58 +03:00
|
|
|
free(line);
|
|
|
|
free(temp);
|
2023-11-26 13:12:57 +03:00
|
|
|
return vendor_list;
|
|
|
|
}
|
|
|
|
|
2023-11-26 18:23:58 +03:00
|
|
|
static void print_vendors(uint64_t num_vendors, vendor_t **vendor_list) {
|
2023-11-26 13:12:57 +03:00
|
|
|
for (uint64_t i = 0; i < num_vendors; i++) {
|
2023-11-26 18:23:58 +03:00
|
|
|
vendor_t *vendor = vendor_list[i];
|
2023-11-26 13:12:57 +03:00
|
|
|
fb_printf("ID: 0x%x, Name: %s\n", vendor->id, vendor->name);
|
|
|
|
}
|
|
|
|
}
|
2023-11-13 22:54:24 +03:00
|
|
|
|
2023-11-18 14:50:37 +03:00
|
|
|
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
2023-11-07 22:31:24 +03:00
|
|
|
init_env(env);
|
2023-11-25 21:22:34 +03:00
|
|
|
|
|
|
|
module_info_t *pci_data = get_module("[PCI][DATA][VENDORS]");
|
|
|
|
|
2023-11-29 00:11:15 +03:00
|
|
|
if (pci_data == NULL) { fb_printf("База PCI не найдена!\n"); }
|
2023-11-25 21:22:34 +03:00
|
|
|
|
2023-11-26 18:23:58 +03:00
|
|
|
uint64_t num_vendors = count_chars(pci_data->data, ';');
|
2023-11-25 21:22:34 +03:00
|
|
|
fb_printf("Количество вендоров: %u\n", num_vendors);
|
2023-11-26 13:12:57 +03:00
|
|
|
|
2023-12-12 21:11:06 +03:00
|
|
|
vendor_t **vendor_list = parse_file(pci_data->data, num_vendors, pci_data->data_size);
|
2023-11-26 13:12:57 +03:00
|
|
|
// print_vendors(num_vendors, vendor_list);
|
2023-12-15 18:00:19 +03:00
|
|
|
return (module_info_t){ .name = (char *)"[PCI][ADAPTER]",
|
|
|
|
.message = (char *)"PCI данные",
|
|
|
|
.type = 0,
|
|
|
|
.data_size = num_vendors,
|
|
|
|
.data = vendor_list,
|
|
|
|
.err_code = 0,
|
|
|
|
.module_id = 0,
|
|
|
|
.irq = 0,
|
|
|
|
.irq_handler = 0,
|
2024-01-21 19:25:04 +03:00
|
|
|
.get_func = 0,
|
|
|
|
.after_init = 0 };
|
2023-11-07 22:31:24 +03:00
|
|
|
}
|