Add a few Linux compatibility shims
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/kern/include/linux/compat_todo.h b/kern/include/linux/compat_todo.h
index 096293d..32836ca 100644
--- a/kern/include/linux/compat_todo.h
+++ b/kern/include/linux/compat_todo.h
@@ -241,6 +241,13 @@
// XXX t->state = 2
}
+static inline void tasklet_kill(struct tasklet_struct *t)
+{
+ /* This is some hokey shit. The one user of this is trying to kill it
+ * after it already ran too. This is more of a 'disable' in Linux. */
+ atomic_cas_u32(&t->state, 1, 0);
+}
+
static inline void tasklet_init(struct tasklet_struct *t,
void (*func)(unsigned long), unsigned long data)
{
@@ -305,6 +312,13 @@
return round_jiffies(j);
}
+static inline unsigned long msecs_to_jiffies(const unsigned int m)
+{
+ return m;
+}
+
+#define time_after_eq(a, b) ((b) <= (a))
+
struct timer_list {
spinlock_t lock;
bool scheduled;
@@ -641,13 +655,14 @@
struct dma_pool *dma_pool_create(const char *name, void *dev,
size_t size, size_t align, size_t allocation);
-
void dma_pool_destroy(struct dma_pool *pool);
-
void *dma_pool_alloc(struct dma_pool *pool, int mem_flags, dma_addr_t *handle);
-
+void *dma_pool_zalloc(struct dma_pool *pool, int mem_flags, dma_addr_t *handle);
void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t addr);
+/* This leaks memory, but we don't do driver detach yet. */
+#define dmam_pool_create dma_pool_create
+
#define pci_pool dma_pool
#define pci_pool_create(name, pdev, size, align, allocation) \
dma_pool_create(name, pdev, size, align, allocation)
@@ -736,6 +751,7 @@
#define vmalloc_node(...) (0 /* XXX */)
/* needed by icm.c: */
#define kmalloc_node(size, flags, node) kmalloc(size, flags)
+/* MLX4 icm.c calls this, it fails, and tries something else */
#define alloc_pages_node(nid, gfp_mask, order) 0
struct scatterlist {
@@ -1069,6 +1085,7 @@
#define for_each_online_cpu(x) for_each_core(x)
#define alloc_percpu_gfp(x, f) percpu_alloc(x, f)
+#define alloc_percpu(x) percpu_alloc(x, MEM_WAIT)
#define free_percpu(x) percpu_free(x)
#define __this_cpu_read(x) PERCPU_VAR(x)
diff --git a/kern/include/linux_compat.h b/kern/include/linux_compat.h
index c645057..37af5f9 100644
--- a/kern/include/linux_compat.h
+++ b/kern/include/linux_compat.h
@@ -37,6 +37,14 @@
//#define CONFIG_INET 1 // will deal with this manually
#define CONFIG_PCI_MSI 1
+#define IS_ENABLED(x) defined(x)
+
+struct module;
+#define __module_get(x)
+#define module_put(x)
+#define try_module_get(x) true
+#define kref_get(p) kref_get(p, 1)
+
static inline void synchronize_sched(void)
{
synchronize_rcu();
@@ -160,6 +168,11 @@
#define dma_mapping_error(dev, handle) \
__dma_mapping_error(handle)
+static inline void *devm_kzalloc(struct device *dev, size_t amt, int flags)
+{
+ return kzmalloc(amt, flags);
+}
+
static void *vmalloc(size_t size)
{
void *vaddr = get_cont_pages(LOG2_UP(nr_pages(size)), MEM_WAIT);
@@ -176,6 +189,16 @@
free_cont_pages(vaddr, LOG2_UP(nr_pages(size)));
}
+/* Linux's helper, adapted to Akaros. Any usage of __flags is likely wrong. */
+#define KMEM_CACHE(__struct, __flags) \
+({ \
+ static_assert(__flags == 0); \
+ kmem_cache_create(#__struct, sizeof(struct __struct), \
+ __alignof__(struct __struct), 0, NULL, NULL, \
+ NULL, NULL); \
+})
+
+
typedef int pci_power_t;
typedef int pm_message_t;
@@ -267,6 +290,18 @@
#define dev_alert(dev, fmt, ...) \
printk("[dev]: " fmt, ##__VA_ARGS__)
+/* Turn it on per-file with #define DEV_DBG */
+#ifdef DEV_DBG
+ #define dev_dbg(dev, fmt, ...) \
+ printk("[dev]: " fmt, ##__VA_ARGS__)
+#else
+ #define dev_dbg(dev, fmt, ...)
+#endif
+
+#define dev_dbg_ratelimited dev_dbg
+#define dev_WARN(dev, fmt, ...) \
+ warn("[dev]: " fmt, ##__VA_ARGS__)
+
#ifdef DEBUG
#define might_sleep() assert(can_block(&per_cpu_info[core_id()]))
@@ -307,6 +342,7 @@
#define MODULE_VERSION(...)
#define MODULE_FIRMWARE(...)
#define module_param(...)
+#define module_param_string(...)
#define module_param_named(...)
#define MODULE_PARM_DESC(...)
#define MODULE_DEVICE_TABLE(...)
@@ -316,6 +352,12 @@
#define module_init(...)
#define module_exit(...)
+/* Feel free to add more. If we get too many of these, we may need to think of
+ * when we are running them. Right now, they all happen after arch and rcu
+ * init, and before devtab reset/init. */
+#define arch_initcall(x) init_func_2(x)
+#define device_initcall(x) init_func_2(x)
+
#define is_kdump_kernel() (0)
/* from Linux's ethtool.h. We probably won't use any of this code, but at
@@ -594,7 +636,7 @@
#define rtnl_unlock()
#define ASSERT_RTNL(...)
-#define synchronize_irq(x) warn_once("Asked to sync IRQ %d, unsupported", x)
+#define synchronize_irq(x) synchronize_rcu()
#define HZ 1000
/* Linux has a PCI device id struct. Drivers make tables of their supported
@@ -640,6 +682,7 @@
#define PCI_VENDOR_ID_AT 0x1259
#define PCI_VENDOR_ID_LINKSYS 0x1737
#define PCI_VENDOR_ID_GIGABYTE 0x1458
+#define PCI_VENDOR_ID_INTEL 0x8086
/* I'd like to spatch all of the pci methods, but I don't know how to do the
* reads. Since we're not doing the reads, then no sense doing the writes. */
@@ -696,6 +739,32 @@
return 0;
}
+static inline int pci_enable_device_mem(struct pci_device *dev)
+{
+ return pci_enable_device(dev);
+}
+
+static inline int pci_save_state(struct pci_device *dev)
+{
+ return 0;
+}
+
+static inline void pci_restore_state(struct pci_device *dev)
+{
+}
+
+static inline void pci_enable_pcie_error_reporting(struct pci_device *dev)
+{
+}
+
+static inline void pci_disable_pcie_error_reporting(struct pci_device *dev)
+{
+}
+
+static inline void pci_wake_from_d3(struct pci_device *dev, bool foo)
+{
+}
+
static inline uint32_t pci_resource_len(struct pci_device *dev, int bir)
{
return pci_get_membar_sz(dev, bir);
diff --git a/kern/src/dmapool.c b/kern/src/dmapool.c
index f714cdd..b6d7f8e 100644
--- a/kern/src/dmapool.c
+++ b/kern/src/dmapool.c
@@ -161,6 +161,16 @@
return retval;
}
+void *dma_pool_zalloc(struct dma_pool *pool, int mem_flags, dma_addr_t *handle)
+{
+ void *ret = dma_pool_alloc(pool, mem_flags, handle);
+
+ if (!ret)
+ return NULL;
+ memset(ret, 0, pool->size);
+ return ret;
+}
+
void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t addr)
{
/* TODO */