From a9116ea8dbf06b9ba1d53ffbe7eabaea8b63cd29 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 1 Jan 2019 16:43:20 -0500 Subject: [PATCH] freebsd_network: Add an "id" field to struct device_method. "const char* name" is alright for the compat layer's needs to identify functions, as we only scan the method table once and copy the function pointers to a struct of function pointers. iflib doesn't use a function pointer struct, though, and expects to have the KOBJ system for function lookups, and that depends on integer-based method IDs for fast lookups. So now every method gets an integer ID as well as a name (and iflib's method IDs are in the list of method IDs already.) --- .../freebsd_network/compat/sys/haiku-module.h | 38 +++++---- .../freebsd_network/compat/sys/method-ids.h | 83 +++++++++++++++++++ 2 files changed, 105 insertions(+), 16 deletions(-) create mode 100644 src/libs/compat/freebsd_network/compat/sys/method-ids.h diff --git a/src/libs/compat/freebsd_network/compat/sys/haiku-module.h b/src/libs/compat/freebsd_network/compat/sys/haiku-module.h index 10450275b1..13f29113f5 100644 --- a/src/libs/compat/freebsd_network/compat/sys/haiku-module.h +++ b/src/libs/compat/freebsd_network/compat/sys/haiku-module.h @@ -11,6 +11,7 @@ #include #include +#include #undef __unused #define __unused @@ -45,25 +46,40 @@ typedef void miibus_statchg_t(device_t dev); typedef void miibus_linkchg_t(device_t dev); typedef void miibus_mediainit_t(device_t dev); + struct device_method { - const char *name; + const char* name; + const int32 id; + /* interfaces w/o function pointer structs use IDs for method lookups */ device_method_signature_t method; }; typedef struct device_method device_method_t; -#define DEVMETHOD(name, func) { #name, (device_method_signature_t)&func } -#define DEVMETHOD_END { 0, 0 } +#define DEVMETHOD(name, func) { #name, ID_##name, (device_method_signature_t)&func } +#define DEVMETHOD_END { 0, 0 } + typedef struct { - const char *name; - device_method_t *methods; - size_t size; + const char* name; + device_method_t* methods; + size_t size; /* softc size */ } driver_t; +#define DEFINE_CLASS_0(name, driver, methods, size) \ + driver_t driver = { #name, methods, size } + +#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ + driver_t *DRIVER_MODULE_NAME(name, busname) = &(driver); \ + devclass_t *__class_ ## name ## _ ## busname ## _ ## devclass = &(devclass) + +#define DRIVER_MODULE_ORDERED(name, busname, driver, devclass, evh, arg, order) \ + DRIVER_MODULE(name, busname, driver, devclass, evh, arg) + #define DRIVER_MODULE_NAME(name, busname) \ __fbsd_ ## name ## _ ## busname + status_t _fbsd_init_drivers(driver_t *driver[]); status_t _fbsd_uninit_drivers(driver_t *driver[]); @@ -247,16 +263,6 @@ extern const char* __haiku_firmware_name_map[][2]; HAIKU_INTR_REGISTER_LEAVE(); \ } while (0) -#define DEFINE_CLASS_0(name, driver, methods, size) \ - driver_t driver = { #name, methods, size } - -#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ - driver_t *DRIVER_MODULE_NAME(name, busname) = &(driver); \ - devclass_t *__class_ ## name ## _ ## busname ## _ ## devclass = &(devclass) - -#define DRIVER_MODULE_ORDERED(name, busname, driver, devclass, evh, arg, order) \ - DRIVER_MODULE(name, busname, driver, devclass, evh, arg) - #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) #endif /* _FBSD_COMPAT_SYS_HAIKU_MODULE_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/method-ids.h b/src/libs/compat/freebsd_network/compat/sys/method-ids.h new file mode 100644 index 0000000000..c9f56306a5 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/method-ids.h @@ -0,0 +1,83 @@ +/* + * Copyright 2019, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_METHOD_IDS_H +#define _FBSD_COMPAT_SYS_METHOD_IDS_H + + +enum device_method_ids { + ID_device_register = 1, + ID_device_probe, + ID_device_attach, + ID_device_detach, + ID_device_suspend, + ID_device_resume, + ID_device_shutdown, + + ID_miibus_readreg, + ID_miibus_writereg, + ID_miibus_statchg, + ID_miibus_linkchg, + ID_miibus_mediainit, + + ID_bus_child_location_str, + ID_bus_child_pnpinfo_str, + ID_bus_hinted_child, + ID_bus_print_child, + ID_bus_read_ivar, + + ID_ifdi_knlist_add, + ID_ifdi_knote_event, + ID_ifdi_object_info_get, + ID_ifdi_attach_pre, + ID_ifdi_attach_post, + ID_ifdi_reinit_pre, + ID_ifdi_reinit_post, + ID_ifdi_cloneattach, + ID_ifdi_detach, + ID_ifdi_suspend, + ID_ifdi_shutdown, + ID_ifdi_resume, + ID_ifdi_tx_queues_alloc, + ID_ifdi_rx_queues_alloc, + ID_ifdi_queues_free, + ID_ifdi_rx_clset, + ID_ifdi_init, + ID_ifdi_stop, + ID_ifdi_msix_intr_assign, + ID_ifdi_intr_enable, + ID_ifdi_intr_disable, + ID_ifdi_rx_queue_intr_enable, + ID_ifdi_tx_queue_intr_enable, + ID_ifdi_link_intr_enable, + ID_ifdi_multi_set, + ID_ifdi_mtu_set, + ID_ifdi_mac_set, + ID_ifdi_media_set, + ID_ifdi_promisc_set, + ID_ifdi_crcstrip_set, + ID_ifdi_vflr_handle, + ID_ifdi_iov_init, + ID_ifdi_iov_uninit, + ID_ifdi_iov_vf_add, + ID_ifdi_update_admin_status, + ID_ifdi_media_status, + ID_ifdi_media_change, + ID_ifdi_get_counter, + ID_ifdi_priv_ioctl, + ID_ifdi_i2c_req, + ID_ifdi_txq_setup, + ID_ifdi_rxq_setup, + ID_ifdi_timer, + ID_ifdi_watchdog_reset, + ID_ifdi_watchdog_reset_queue, + ID_ifdi_led_func, + ID_ifdi_vlan_register, + ID_ifdi_vlan_unregister, + ID_ifdi_sysctl_int_delay, + ID_ifdi_debug, +}; + + +#endif /* _FBSD_COMPAT_SYS_METHOD_IDS_H */