From 0a1664b892c168ec238819fb01fd56b8f9f829e0 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Tue, 12 May 2015 15:16:19 +0200 Subject: [PATCH] usb_drv: remove dde_kit issue #1565 --- repos/dde_linux/lib/mk/arm/usb.inc | 4 +- repos/dde_linux/lib/mk/usb.inc | 3 +- repos/dde_linux/run/usb_hid.run | 2 +- repos/dde_linux/src/drivers/usb/target.mk | 2 +- .../{platform_device.c => platform_device.cc} | 31 +- .../src/lib/usb/arm/platform_rpi/platform.cc | 18 +- repos/dde_linux/src/lib/usb/dummies.c | 10 +- repos/dde_linux/src/lib/usb/include/list.h | 102 +++++ repos/dde_linux/src/lib/usb/include/lx_emul.h | 149 +++++--- repos/dde_linux/src/lib/usb/include/routine.h | 10 +- repos/dde_linux/src/lib/usb/input/evdev.c | 4 +- repos/dde_linux/src/lib/usb/lx_emul.cc | 138 +++---- repos/dde_linux/src/lib/usb/main.cc | 7 - repos/dde_linux/src/lib/usb/nic/nic.cc | 12 +- repos/dde_linux/src/lib/usb/pci_driver.cc | 127 +++++- repos/dde_linux/src/lib/usb/signal/event.cc | 18 +- repos/dde_linux/src/lib/usb/signal/irq.cc | 4 +- repos/dde_linux/src/lib/usb/signal/timer.cc | 360 ++++++++++++++---- repos/dde_linux/src/lib/usb/storage/scsi.c | 8 +- 19 files changed, 705 insertions(+), 304 deletions(-) rename repos/dde_linux/src/lib/usb/arm/{platform_device.c => platform_device.cc} (85%) create mode 100644 repos/dde_linux/src/lib/usb/include/list.h diff --git a/repos/dde_linux/lib/mk/arm/usb.inc b/repos/dde_linux/lib/mk/arm/usb.inc index ae88dd219..518991b2d 100644 --- a/repos/dde_linux/lib/mk/arm/usb.inc +++ b/repos/dde_linux/lib/mk/arm/usb.inc @@ -1,4 +1,4 @@ -SRC_C += platform_device.c +SRC_CC += platform_device.c INC_DIR += $(LIB_INC_DIR)/arm -vpath platform_device.c $(LIB_DIR)/arm +vpath platform_device.cc $(LIB_DIR)/arm diff --git a/repos/dde_linux/lib/mk/usb.inc b/repos/dde_linux/lib/mk/usb.inc index 04d1498b0..e8c98a01c 100644 --- a/repos/dde_linux/lib/mk/usb.inc +++ b/repos/dde_linux/lib/mk/usb.inc @@ -1,8 +1,7 @@ LIB_DIR = $(REP_DIR)/src/lib/usb LIB_INC_DIR = $(LIB_DIR)/include -# FIXME should we *really* dde_kit to this shared library? -LIBS += dde_kit libc-setjmp config +LIBS += libc-setjmp config SRC_CC += main.cc lx_emul.cc irq.cc timer.cc event.cc storage.cc \ input_component.cc nic.cc raw.cc SRC_C += dummies.c scsi.c evdev.c raw_driver.c diff --git a/repos/dde_linux/run/usb_hid.run b/repos/dde_linux/run/usb_hid.run index deac8a581..d4f639a49 100644 --- a/repos/dde_linux/run/usb_hid.run +++ b/repos/dde_linux/run/usb_hid.run @@ -56,7 +56,7 @@ append config { - + diff --git a/repos/dde_linux/src/drivers/usb/target.mk b/repos/dde_linux/src/drivers/usb/target.mk index 8d7ccfc72..7cb1b6e78 100644 --- a/repos/dde_linux/src/drivers/usb/target.mk +++ b/repos/dde_linux/src/drivers/usb/target.mk @@ -1,3 +1,3 @@ TARGET = usb_drv SRC_CC = main.cc -LIBS = usb server +LIBS = base usb server diff --git a/repos/dde_linux/src/lib/usb/arm/platform_device.c b/repos/dde_linux/src/lib/usb/arm/platform_device.cc similarity index 85% rename from repos/dde_linux/src/lib/usb/arm/platform_device.c rename to repos/dde_linux/src/lib/usb/arm/platform_device.cc index d974df3f8..866f9fd26 100644 --- a/repos/dde_linux/src/lib/usb/arm/platform_device.c +++ b/repos/dde_linux/src/lib/usb/arm/platform_device.cc @@ -11,7 +11,13 @@ * under the terms of the GNU General Public License version 2. */ +#include + +#include #include +#include + + #define to_platform_driver(drv) (container_of((drv), struct platform_driver, \ driver)) @@ -38,13 +44,15 @@ static int platform_drv_probe(struct device *_dev) struct bus_type platform_bus_type = { .name = "platform", - .match = platform_match, - .probe = platform_drv_probe }; int platform_driver_register(struct platform_driver *drv) { + /* init plarform_bus_type */ + platform_bus_type.match = platform_match; + platform_bus_type.probe = platform_drv_probe; + drv->driver.bus = &platform_bus_type; if (drv->probe) drv->driver.probe = platform_drv_probe; @@ -57,7 +65,7 @@ int platform_driver_register(struct platform_driver *drv) struct resource *platform_get_resource(struct platform_device *dev, unsigned int type, unsigned int num) { - int i; + unsigned i; for (i = 0; i < dev->num_resources; i++) { struct resource *r = &dev->resource[i]; @@ -74,7 +82,7 @@ struct resource *platform_get_resource_byname(struct platform_device *dev, unsigned int type, const char *name) { - int i; + unsigned i; for (i = 0; i < dev->num_resources; i++) { struct resource *r = &dev->resource[i]; @@ -115,13 +123,13 @@ int platform_device_register(struct platform_device *pdev) struct platform_device *platform_device_alloc(const char *name, int id) { - struct platform_device *pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL); + platform_device *pdev = (platform_device *)kzalloc(sizeof(struct platform_device), GFP_KERNEL); if (!pdev) return 0; int len = strlen(name); - pdev->name = kzalloc(len + 1, GFP_KERNEL); + pdev->name = (char *)kzalloc(len + 1, GFP_KERNEL); if (!pdev->name) { kfree(pdev); @@ -162,7 +170,7 @@ int platform_device_add_resources(struct platform_device *pdev, struct resource *r = NULL; if (res) { - r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL); + r = (resource *)kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL); if (!r) return -ENOMEM; } @@ -192,12 +200,15 @@ void platform_set_drvdata(struct platform_device *pdev, void *data) void *_ioremap(resource_size_t phys_addr, unsigned long size, int wc) { - dde_kit_addr_t map_addr; - if (dde_kit_request_mem(phys_addr, size, wc, &map_addr)) { + try { + Genode::Attached_io_mem_dataspace *ds = new(Genode::env()->heap()) + Genode::Attached_io_mem_dataspace(phys_addr, size, !!wc); + /* map base + page offset */ + return ds->local_addr() + (phys_addr & (PAGE_SIZE - 1)); + } catch (...) { panic("Failed to request I/O memory: [%zx,%lx)", phys_addr, phys_addr + size); return 0; } - return (void *)map_addr; } diff --git a/repos/dde_linux/src/lib/usb/arm/platform_rpi/platform.cc b/repos/dde_linux/src/lib/usb/arm/platform_rpi/platform.cc index 6cacb6dcc..52a988721 100644 --- a/repos/dde_linux/src/lib/usb/arm/platform_rpi/platform.cc +++ b/repos/dde_linux/src/lib/usb/arm/platform_rpi/platform.cc @@ -57,14 +57,14 @@ static resource _dwc_otg_resource[] = ***************************************/ #if VERBOSE_LX_EMUL -#define TRACE dde_kit_printf("\033[32m%s\033[0m called, not implemented\n", __PRETTY_FUNCTION__) +#define TRACE lx_printf("\033[32m%s\033[0m called, not implemented\n", __PRETTY_FUNCTION__) #else #define TRACE #endif #define DUMMY(retval, name) \ extern "C" long name() { \ - dde_kit_printf("\033[32m%s\033[0m called, not implemented, stop\n", #name); \ + lx_printf("\033[32m%s\033[0m called, not implemented, stop\n", #name); \ bt(); \ for (;;); \ return retval; \ @@ -72,7 +72,7 @@ extern "C" long name() { \ #define CHECKED_DUMMY(retval, name) \ extern "C" long name() { \ - dde_kit_printf("\033[32m%s\033[0m called, not implemented, ignored\n", #name); \ + lx_printf("\033[32m%s\033[0m called, not implemented, ignored\n", #name); \ bt(); \ return retval; \ } @@ -98,18 +98,6 @@ int in_irq() unsigned long loops_per_jiffy = 1; - -/********************* - ** linux/jiffies.h ** - *********************/ - -unsigned int jiffies_to_msecs(const unsigned long j) -{ - PDBG("not implemented. stop"); - return 1; -} - - /*********************************** ** Dummies for unused PCD driver ** ***********************************/ diff --git a/repos/dde_linux/src/lib/usb/dummies.c b/repos/dde_linux/src/lib/usb/dummies.c index 0f9629671..9b48f3692 100644 --- a/repos/dde_linux/src/lib/usb/dummies.c +++ b/repos/dde_linux/src/lib/usb/dummies.c @@ -16,21 +16,18 @@ /* Linux kernel API */ #include -/* DDE-Kit includes */ -#include - /* Linux includes */ #include #define SKIP_VERBOSE 0 #if DEBUG_TRACE -#define TRACE dde_kit_printf("\033[32m%s\033[0m called from %p, not implemented\n", __PRETTY_FUNCTION__, __builtin_return_address(0)) +#define TRACE lx_printf("\033[32m%s\033[0m called from %p, not implemented\n", __PRETTY_FUNCTION__, __builtin_return_address(0)) #else #define TRACE #endif #if SKIP_VERBOSE -#define SKIP dde_kit_printf("\033[34m%s\033[0m: skipped\n", __PRETTY_FUNCTION__) +#define SKIP lx_printf("\033[34m%s\033[0m: skipped\n", __PRETTY_FUNCTION__) #else #define SKIP #endif @@ -137,6 +134,9 @@ void assert_spin_locked(spinlock_t *lock) { TRACE;} void mutex_lock_nested(struct mutex *lock, unsigned int subclass) { TRACE; } int mutex_lock_interruptible(struct mutex *m) { TRACE; return 0; } +void mutex_init (struct mutex *m) { TRACE; } +void mutex_lock (struct mutex *m) { TRACE; } +void mutex_unlock(struct mutex *m) { TRACE; } /******************* diff --git a/repos/dde_linux/src/lib/usb/include/list.h b/repos/dde_linux/src/lib/usb/include/list.h new file mode 100644 index 000000000..c12fdaf1a --- /dev/null +++ b/repos/dde_linux/src/lib/usb/include/list.h @@ -0,0 +1,102 @@ +/* + * \brief Slightly improved list + * \author Christian Helmuth + * \date 2014-09-25 + */ + +/* + * Copyright (C) 2014 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _LIST_H_ +#define _LIST_H_ + +#include + + +namespace Lx { + template class List; + template class List_element; +} + +template +class Lx::List : private Genode::List +{ + private: + + typedef Genode::List Base; + + public: + + using Base::Element; + + void append(LT const *le) + { + LT *at = nullptr; + + for (LT *l = first(); l; l = l->next()) + at = l; + + Base::insert(le, at); + } + + void prepend(LT const *le) + { + Base::insert(le); + } + + void insert_before(LT const *le, LT const *at) + { + if (at == first()) { + prepend(le); + return; + } else if (!at) { + append(le); + return; + } + + for (LT *l = first(); l; l = l->next()) + if (l->next() == at) + at = l; + + Base::insert(le, at); + } + + + /**************************** + ** Genode::List interface ** + ****************************/ + + LT *first() { return Base::first(); } + LT const *first() const { return Base::first(); } + + void insert(LT const *le, LT const *at = 0) + { + Base::insert(le, at); + } + + void remove(LT const *le) + { + Base::remove(le); + } +}; + + +template +class Lx::List_element : public Lx::List >::Element +{ + private: + + T *_object; + + public: + + List_element(T *object) : _object(object) { } + + T *object() const { return _object; } +}; + +#endif /* _LIST_H_ */ diff --git a/repos/dde_linux/src/lib/usb/include/lx_emul.h b/repos/dde_linux/src/lib/usb/include/lx_emul.h index 65cb28e7a..eefdd2f6a 100644 --- a/repos/dde_linux/src/lib/usb/include/lx_emul.h +++ b/repos/dde_linux/src/lib/usb/include/lx_emul.h @@ -18,15 +18,8 @@ #ifndef _LX_EMUL_H_ #define _LX_EMUL_H_ -/* DDE Kit includes */ -#include -#include -#include -#include -#include -#include -#include - +#include +#include #define DEBUG_COMPLETION 0 #define DEBUG_DMA 0 @@ -46,10 +39,21 @@ #define KBUILD_MODNAME "mod-noname" +void lx_printf(char const *, ...) __attribute__((format(printf, 1, 2))); +void lx_vprintf(char const *, va_list); + +#define lx_log(doit, msg...) \ + do { \ + if (doit) { \ + lx_printf("%s(): ", __func__); \ + lx_printf(msg); \ + lx_printf("\n"); \ + } \ + } while(0); static inline void bt() { - dde_kit_printf("BT: 0x%p\n", __builtin_return_address(0)); + lx_printf("BT: 0x%p\n", __builtin_return_address(0)); } @@ -72,16 +76,16 @@ static inline void bt() #define WARN_ON(condition) ({ \ int ret = !!(condition); \ - if (ret) dde_kit_debug("[%s] WARN_ON(" #condition ") ", __func__); \ + if (ret) lx_printf("[%s] WARN_ON(" #condition ") ", __func__); \ ret; }) #define WARN(condition, fmt, arg...) ({ \ int ret = !!(condition); \ - if (ret) dde_kit_debug("[%s] *WARN* " fmt , __func__ , ##arg); \ + if (ret) lx_printf("[%s] *WARN* " fmt , __func__ , ##arg); \ ret; }) #define BUG() do { \ - dde_kit_debug("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ + lx_printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ while (1); \ } while (0) @@ -133,15 +137,15 @@ int atomic_inc_return(atomic_t *v); ** linux/types.h ** *******************/ -typedef dde_kit_int8_t int8_t; -typedef dde_kit_uint8_t uint8_t; -typedef dde_kit_int16_t int16_t; -typedef dde_kit_uint16_t uint16_t; -typedef dde_kit_int32_t int32_t; -typedef dde_kit_uint32_t uint32_t; -typedef dde_kit_size_t size_t; -typedef dde_kit_int64_t int64_t; -typedef dde_kit_uint64_t uint64_t; +typedef genode_int8_t int8_t; +typedef genode_uint8_t uint8_t; +typedef genode_int16_t int16_t; +typedef genode_uint16_t uint16_t; +typedef genode_int32_t int32_t; +typedef genode_uint32_t uint32_t; +typedef __SIZE_TYPE__ size_t; +typedef genode_int64_t int64_t; +typedef genode_uint64_t uint64_t; typedef uint32_t uint; typedef unsigned long ulong; @@ -292,14 +296,18 @@ typedef unsigned short ushort; #define __printf(a, b) __attribute__((format(printf, a, b))) +/************************** + ** linux/compiler-gcc.h ** + **************************/ + +#define __noreturn __attribute__((noreturn)) + /********************* ** linux/jiffies.h ** *********************/ /* we directly map 'jiffies' to 'dde_kit_timer_ticks' */ -#define jiffies dde_kit_timer_ticks - -extern volatile unsigned long jiffies; +extern unsigned long jiffies; unsigned long msecs_to_jiffies(const unsigned int m); unsigned int jiffies_to_msecs(const unsigned long j); long time_after(long a, long b); @@ -535,15 +543,24 @@ enum { * Debug macros */ #if DEBUG_PRINTK -#define printk dde_kit_printf -#define vprintk dde_kit_vprintf -#define panic dde_kit_panic +#define printk _printk +#define vprintk _lx_vprintf #else #define printk(...) #define vprintk(...) -#define panic(...) #endif +static inline __printf(1, 2) void panic(const char *fmt, ...) __noreturn; +static inline void panic(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + lx_vprintf(fmt, args); + va_end(args); + lx_printf("panic()"); + while (1) ; +} + /* * Bits and types */ @@ -717,6 +734,16 @@ struct va_format va_list *va; }; +static inline int _printk(const char *fmt, ...) __attribute__((format(printf, 1, 2))); +static inline int _printk(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + lx_vprintf(fmt, args); + va_end(args); + return 0; +} + /********************************** ** linux/bitops.h, asm/bitops.h ** **********************************/ @@ -907,13 +934,13 @@ void *kcalloc(size_t n, size_t size, gfp_t flags); struct kmem_cache; /** - * Create slab cache using DDE kit + * Create slab cache */ struct kmem_cache *kmem_cache_create(const char *, size_t, size_t, unsigned long, void (*)(void *)); /** - * Destroy slab cache using DDE kit + * Destroy slab cache */ void kmem_cache_destroy(struct kmem_cache *); @@ -937,7 +964,7 @@ void kmem_cache_free(struct kmem_cache *, void *); ** linux/spinlock.h ** **********************/ -typedef dde_kit_spin_lock spinlock_t; +typedef uint32_t spinlock_t; #define DEFINE_SPINLOCK(name) spinlock_t name = 0; void spin_lock(spinlock_t *lock); @@ -956,7 +983,7 @@ void assert_spin_locked(spinlock_t *lock); ** linux/mutex.h ** *******************/ -struct mutex { struct dde_kit_lock *lock; }; +struct mutex { uint8_t d; }; void mutex_init(struct mutex *m); void mutex_lock(struct mutex *m); @@ -964,7 +991,7 @@ void mutex_lock_nested(struct mutex *lock, unsigned int subclass); void mutex_unlock(struct mutex *m); int mutex_lock_interruptible(struct mutex *m); -#define DEFINE_MUTEX(mutexname) struct mutex mutexname = { NULL }; +#define DEFINE_MUTEX(mutexname) struct mutex mutexname = { 0 }; /*********************** @@ -1586,27 +1613,27 @@ bool device_can_wakeup(struct device *dev); ** linux/device.h ** ********************/ -#define dev_info(dev, format, arg...) dde_kit_printf("dev_info: " format, ## arg) -#define dev_warn(dev, format, arg...) dde_kit_printf("dev_warn: " format, ## arg) -#define dev_WARN(dev, format, arg...) dde_kit_printf("dev_WARN: " format, ## arg) -#define dev_err( dev, format, arg...) dde_kit_printf("dev_error: " format, ## arg) -#define dev_notice(dev, format, arg...) dde_kit_printf("dev_notice: " format, ## arg) +#define dev_info(dev, format, arg...) lx_printf("dev_info: " format, ## arg) +#define dev_warn(dev, format, arg...) lx_printf("dev_warn: " format, ## arg) +#define dev_WARN(dev, format, arg...) lx_printf("dev_WARN: " format, ## arg) +#define dev_err( dev, format, arg...) lx_printf("dev_error: " format, ## arg) +#define dev_notice(dev, format, arg...) lx_printf("dev_notice: " format, ## arg) #define dev_dbg_ratelimited(dev, format, arg...) #if DEBUG_PRINTK -#define dev_dbg(dev, format, arg...) dde_kit_printf("dev_dbg: " format, ## arg) -#define dev_vdbg(dev, format, arg...) dde_kit_printf("dev_dbg: " format, ## arg) +#define dev_dbg(dev, format, arg...) lx_printf("dev_dbg: " format, ## arg) +#define dev_vdbg(dev, format, arg...) lx_printf("dev_dbg: " format, ## arg) #else #define dev_dbg( dev, format, arg...) #define dev_vdbg( dev, format, arg...) #endif #define dev_printk(level, dev, format, arg...) \ - dde_kit_printf("dev_printk: " format, ## arg) + lx_printf("dev_printk: " format, ## arg) #define dev_warn_ratelimited(dev, format, arg...) \ - dde_kit_printf("dev_warn_ratelimited: " format "\n", ## arg) + lx_printf("dev_warn_ratelimited: " format "\n", ## arg) enum { BUS_NOTIFY_ADD_DEVICE = 0x00000001, @@ -1866,8 +1893,8 @@ bool access_ok(int access, void *addr, size_t size); size_t copy_from_user(void *to, void const *from, size_t len); size_t copy_to_user(void *dst, void const *src, size_t len); -#define get_user(x, ptr) ({ dde_kit_printf("get_user not implemented"); (0);}) -#define put_user(x, ptr) ({ dde_kit_printf("put_user not implemented"); (0);}) +#define get_user(x, ptr) ({ lx_printf("get_user not implemented"); (0);}) +#define put_user(x, ptr) ({ lx_printf("put_user not implemented"); (0);}) /***************** @@ -2237,13 +2264,13 @@ void *phys_to_virt(unsigned long address); #define readl(addr) (*(volatile uint32_t *)(addr)) #define readb(addr) (*(volatile uint8_t *)(addr)) -static inline void outb(u8 value, u32 port) { dde_kit_outb(port, value); } -static inline void outw(u16 value, u32 port) { dde_kit_outw(port, value); } -static inline void outl(u32 value, u32 port) { dde_kit_outl(port, value); } +void outb(u8 value, u32 port); +void outw(u16 value, u32 port); +void outl(u32 value, u32 port); -static inline u8 inb(u32 port) { return dde_kit_inb(port); } -static inline u16 inw(u32 port) { return dde_kit_inw(port); } -static inline u32 inl(u32 port) { return dde_kit_inl(port); } +u8 inb(u32 port); +u16 inw(u32 port); +u32 inl(u32 port); void native_io_delay(void); @@ -3112,8 +3139,8 @@ struct scsi_device #define to_scsi_device(d) \ container_of(d, struct scsi_device, sdev_gendev) -#define shost_for_each_device(sdev, shost) dde_kit_printf("shost_for_each_device called\n"); -#define __shost_for_each_device(sdev, shost) dde_kit_printf("__shost_for_each_device called\n"); +#define shost_for_each_device(sdev, shost) lx_printf("shost_for_each_device called\n"); +#define __shost_for_each_device(sdev, shost) lx_printf("__shost_for_each_device called\n"); int scsi_device_blocked(struct scsi_device *); int scsi_device_get(struct scsi_device *); @@ -3412,18 +3439,18 @@ int ethtool_op_get_ts_info(struct net_device *, struct ethtool_ts_info *); #include -#define netif_err(priv, type, dev, fmt, args...) dde_kit_printf("netif_err: " fmt, ## args); -#define netif_info(priv, type, dev, fmt, args...) dde_kit_printf("netif_info: " fmt, ## args); +#define netif_err(priv, type, dev, fmt, args...) lx_printf("netif_err: " fmt, ## args); +#define netif_info(priv, type, dev, fmt, args...) lx_printf("netif_info: " fmt, ## args); -#define netdev_err(dev, fmt, args...) dde_kit_printf("nedev_err: " fmt, ##args) -#define netdev_warn(dev, fmt, args...) dde_kit_printf("nedev_warn: " fmt, ##args) -#define netdev_info(dev, fmt, args...) dde_kit_printf("nedev_info: " fmt, ##args) +#define netdev_err(dev, fmt, args...) lx_printf("nedev_err: " fmt, ##args) +#define netdev_warn(dev, fmt, args...) lx_printf("nedev_warn: " fmt, ##args) +#define netdev_info(dev, fmt, args...) lx_printf("nedev_info: " fmt, ##args) #define netdev_for_each_mc_addr(a, b) if (0) #if DEBUG_PRINTK -#define netif_dbg(priv, type, dev, fmt, args...) dde_kit_printf("netif_dbg: " fmt, ## args) -#define netdev_dbg(dev, fmt, args...) dde_kit_printf("netdev_dbg: " fmt, ##args) +#define netif_dbg(priv, type, dev, fmt, args...) lx_printf("netif_dbg: " fmt, ## args) +#define netdev_dbg(dev, fmt, args...) lx_printf("netdev_dbg: " fmt, ##args) #else #define netif_dbg(priv, type, dev, fmt, args...) #define netdev_dbg(dev, fmt, args...) @@ -3755,7 +3782,7 @@ bool of_property_read_bool(const struct device_node *np, const char *propname); ** linux/radix-tree.h ** ************************/ -#define INIT_RADIX_TREE(root, mask) dde_kit_printf("INIT_RADIX_TREE not impelemnted\n") +#define INIT_RADIX_TREE(root, mask) lx_printf("INIT_RADIX_TREE not impelemnted\n") struct radix_tree_root { }; void *radix_tree_lookup(struct radix_tree_root *root, unsigned long index); int radix_tree_insert(struct radix_tree_root *, unsigned long, void *); diff --git a/repos/dde_linux/src/lib/usb/include/routine.h b/repos/dde_linux/src/lib/usb/include/routine.h index 37ca4a0ab..4f3524e76 100644 --- a/repos/dde_linux/src/lib/usb/include/routine.h +++ b/repos/dde_linux/src/lib/usb/include/routine.h @@ -18,15 +18,13 @@ #include #include -extern "C" { -#include -} - #include static const bool verbose = false; - +namespace Timer { + void update_jiffies(); +} /** * Allows pseudo-parallel execution of functions */ @@ -137,6 +135,8 @@ class Routine : public Genode::List::Element if (!_list()->first() && !_main) return; + Timer::update_jiffies(); + if (_current == _main) all = true; diff --git a/repos/dde_linux/src/lib/usb/input/evdev.c b/repos/dde_linux/src/lib/usb/input/evdev.c index 659e9b925..d59e25549 100644 --- a/repos/dde_linux/src/lib/usb/input/evdev.c +++ b/repos/dde_linux/src/lib/usb/input/evdev.c @@ -193,7 +193,7 @@ void genode_evdev_event(struct input_handle *handle, unsigned int type, if (value != -1) { if (slots[slot].id != -1) - dde_kit_printf("warning:: old tracking id in use and got new one\n"); + lx_printf("warning:: old tracking id in use and got new one\n"); slots[slot].id = value; return; @@ -219,7 +219,7 @@ void genode_evdev_event(struct input_handle *handle, unsigned int type, if (disable_multitouch) return; if (value >= sizeof(slots) / sizeof(slots[0])) { - dde_kit_printf("warning: drop slot id %d\n", value); + lx_printf("warning: drop slot id %d\n", value); return; } diff --git a/repos/dde_linux/src/lib/usb/lx_emul.cc b/repos/dde_linux/src/lib/usb/lx_emul.cc index 17d05231f..e64acf978 100644 --- a/repos/dde_linux/src/lib/usb/lx_emul.cc +++ b/repos/dde_linux/src/lib/usb/lx_emul.cc @@ -28,16 +28,6 @@ #include "lx_emul.h" #include -/* DDE kit includes */ -extern "C" { -#include -#include -#include -#include -#include -#include -} - namespace Genode { class Slab_backend_alloc; @@ -54,8 +44,8 @@ class Genode::Slab_backend_alloc : public Genode::Allocator, enum { VM_SIZE = 64 * 1024 * 1024, /* size of VM region to reserve */ - P_BLOCK_SIZE = 1024 * 1024, /* 1 MB physical contiguous */ - V_BLOCK_SIZE = P_BLOCK_SIZE * 2, /* 1 MB virtual used, 1 MB virtual left free to avoid that Allocator_avl merges virtual contiguous regions which are physically non-contiguous */ + P_BLOCK_SIZE = 2 * 1024 * 1024, /* 2 MB physical contiguous */ + V_BLOCK_SIZE = P_BLOCK_SIZE * 2, /* 2 MB virtual used, 2 MB virtual left free to avoid that Allocator_avl merges virtual contiguous regions which are physically non-contiguous */ ELEMENTS = VM_SIZE / V_BLOCK_SIZE /* MAX number of dataspaces in VM */ }; @@ -203,7 +193,7 @@ class Malloc enum { SLAB_START_LOG2 = 3, /* 8 B */ - SLAB_STOP_LOG2 = 16, /* 64 KB */ + SLAB_STOP_LOG2 = 17, /* 128 KB */ NUM_SLABS = (SLAB_STOP_LOG2 - SLAB_START_LOG2) + 1, }; @@ -255,6 +245,8 @@ class Malloc Slab_alloc(1U << i, alloc); } + static unsigned long max_alloc() { return 1U << SLAB_STOP_LOG2; } + /** * Alloc in slabs */ @@ -348,6 +340,19 @@ class Malloc }; +void lx_printf(char const *fmt, ...) +{ + va_list va; + va_start(va, fmt); + Genode::vprintf(fmt, va); + va_end(va); +} + + +void lx_vprintf(char const *fmt, va_list va) { + Genode::vprintf(fmt, va); } + + /*********************** ** Atomic operations ** ***********************/ @@ -366,14 +371,6 @@ void atomic_sub(int i, atomic_t *v) { (*(volatile int *)v) -= i; } void atomic_set(atomic_t *p, unsigned int v) { (*(volatile int *)p) = v; } -/******************* - ** linux/mutex.h ** - *******************/ - -void mutex_init (struct mutex *m) { if (m->lock) dde_kit_lock_init (&m->lock); } -void mutex_lock (struct mutex *m) { if (m->lock) dde_kit_lock_lock ( m->lock); } -void mutex_unlock(struct mutex *m) { if (m->lock) dde_kit_lock_unlock( m->lock); } - /************************************* ** Memory allocation, linux/slab.h ** @@ -427,15 +424,15 @@ void kfree(const void *p) void *vzalloc(unsigned long size) { - void *ptr = dde_kit_simple_malloc(size); - if (ptr) - Genode::memset(ptr, 0, size); + if (size > Malloc::max_alloc()) { + PERR("vzalloc: size %lu > %lu", size, Malloc::max_alloc()); + return 0; + } - return ptr; + return kmalloc(size, 0); } - -void vfree(void *addr) { dde_kit_simple_free(addr); } +void vfree(void *addr) { kfree(addr); } /****************** @@ -444,7 +441,7 @@ void vfree(void *addr) { dde_kit_simple_free(addr); } void kref_init(struct kref *kref) { - dde_kit_log(DEBUG_KREF,"%s ref: %p", __func__, kref); + lx_log(DEBUG_KREF,"%s ref: %p", __func__, kref); kref->refcount.v = 1; } @@ -452,13 +449,13 @@ void kref_init(struct kref *kref) void kref_get(struct kref *kref) { kref->refcount.v++; - dde_kit_log(DEBUG_KREF, "%s ref: %p c: %d", __func__, kref, kref->refcount.v); + lx_log(DEBUG_KREF, "%s ref: %p c: %d", __func__, kref, kref->refcount.v); } int kref_put(struct kref *kref, void (*release) (struct kref *kref)) { - dde_kit_log(DEBUG_KREF, "%s: ref: %p c: %d", __func__, kref, kref->refcount.v); + lx_log(DEBUG_KREF, "%s: ref: %p c: %d", __func__, kref, kref->refcount.v); if (!--kref->refcount.v) { release(kref); @@ -609,15 +606,18 @@ struct kmem_cache { const char *name; /* cache name */ unsigned size; /* object size */ - - struct dde_kit_slab *dde_kit_slab_cache; /* backing DDE kit cache */ }; struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align, unsigned long falgs, void (*ctor)(void *)) { - dde_kit_log(DEBUG_SLAB, "\"%s\" obj_size=%zd", name, size); + lx_log(DEBUG_SLAB, "\"%s\" obj_size=%zd", name, size); + + if (size > Malloc::max_alloc()) { + PERR("kmem_cache_create: slab size > %lu", Malloc::max_alloc()); + return 0; + } struct kmem_cache *cache; @@ -626,19 +626,12 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align return 0; } - cache = (struct kmem_cache *)dde_kit_simple_malloc(sizeof(*cache)); + cache = (struct kmem_cache *)kmalloc(sizeof(*cache), 0); if (!cache) { printk("No memory for slab cache\n"); return 0; } - /* initialize a physically contiguous cache for kmem */ - if (!(cache->dde_kit_slab_cache = dde_kit_slab_init(size))) { - printk("DDE kit slab init failed\n"); - dde_kit_simple_free(cache); - return 0; - } - cache->name = name; cache->size = size; @@ -648,10 +641,8 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align void kmem_cache_destroy(struct kmem_cache *cache) { - dde_kit_log(DEBUG_SLAB, "\"%s\"", cache->name); - - dde_kit_slab_destroy(cache->dde_kit_slab_cache); - dde_kit_simple_free(cache); + lx_log(DEBUG_SLAB, "\"%s\"", cache->name); + kfree(cache); } @@ -659,24 +650,17 @@ void *kmem_cache_zalloc(struct kmem_cache *cache, gfp_t flags) { void *ret; - dde_kit_log(DEBUG_SLAB, "\"%s\" flags=%x", cache->name, flags); - - ret = dde_kit_slab_alloc(cache->dde_kit_slab_cache); - - /* return here in case of error */ - if (!ret) return 0; - - /* zero page */ - memset(ret, 0, cache->size); + lx_log(DEBUG_SLAB, "\"%s\" flags=%x", cache->name, flags); + ret = kzalloc(cache->size, flags); return ret; } void kmem_cache_free(struct kmem_cache *cache, void *objp) { - dde_kit_log(DEBUG_SLAB, "\"%s\" (%p)", cache->name, objp); - dde_kit_slab_free(cache->dde_kit_slab_cache, objp); + lx_log(DEBUG_SLAB, "\"%s\" (%p)", cache->name, objp); + kfree(objp); } @@ -732,7 +716,7 @@ class Driver : public Genode::List::Element return false; bool ret = _drv->bus->match ? _drv->bus->match(dev, _drv) : true; - dde_kit_log(DEBUG_DRIVER, "MATCH: %s ret: %u match: %p %p", + lx_log(DEBUG_DRIVER, "MATCH: %s ret: %u match: %p %p", _drv->name, ret, _drv->bus->match, _drv->probe); return ret; } @@ -745,10 +729,10 @@ class Driver : public Genode::List::Element dev->driver = _drv; if (dev->bus->probe) { - dde_kit_log(DEBUG_DRIVER, "Probing device bus %p", dev->bus->probe); + lx_log(DEBUG_DRIVER, "Probing device bus %p", dev->bus->probe); return dev->bus->probe(dev); } else if (_drv->probe) { - dde_kit_log(DEBUG_DRIVER, "Probing driver: %s %p", _drv->name, _drv->probe); + lx_log(DEBUG_DRIVER, "Probing driver: %s %p", _drv->name, _drv->probe); return _drv->probe(dev); } @@ -759,7 +743,7 @@ class Driver : public Genode::List::Element int driver_register(struct device_driver *drv) { - dde_kit_log(DEBUG_DRIVER, "%s at %p", drv->name, drv); + lx_log(DEBUG_DRIVER, "%s at %p", drv->name, drv); new (Genode::env()->heap()) Driver(drv); return 0; } @@ -774,7 +758,7 @@ int device_add(struct device *dev) for (Driver *driver = Driver::list()->first(); driver; driver = driver->next()) if (driver->match(dev)) { int ret = driver->probe(dev); - dde_kit_log(DEBUG_DRIVER, "Probe return %d", ret); + lx_log(DEBUG_DRIVER, "Probe return %d", ret); if (!ret) return 0; @@ -786,7 +770,7 @@ int device_add(struct device *dev) void device_del(struct device *dev) { - dde_kit_log(DEBUG_DRIVER, "Remove device %p", dev); + lx_log(DEBUG_DRIVER, "Remove device %p", dev); if (dev->driver && dev->driver->remove) dev->driver->remove(dev); } @@ -927,12 +911,11 @@ void mdelay(unsigned long msecs) { msleep(msecs); } ** linux/jiffies.h ** *********************/ -/* - * We use DDE kit's jiffies in 100Hz granularity. - */ -enum { JIFFIES_TICK_MS = 1000 / DDE_KIT_HZ }; +enum { JIFFIES_TICK_MS = 1000 / HZ }; unsigned long msecs_to_jiffies(const unsigned int m) { return m / JIFFIES_TICK_MS; } +unsigned int jiffies_to_msecs(const unsigned long j) { return j * JIFFIES_TICK_MS; } + long time_after_eq(long a, long b) { return (a - b) >= 0; } long time_after(long a, long b) { return (b - a) < 0; } @@ -950,7 +933,7 @@ struct dma_pool struct dma_pool *dma_pool_create(const char *name, struct device *d, size_t size, size_t align, size_t alloc) { - dde_kit_log(DEBUG_DMA, "size: %zx align:%zx %p", size, align, __builtin_return_address((0))); + lx_log(DEBUG_DMA, "size: %zx align:%zx %p", size, align, __builtin_return_address((0))); if (align & (align - 1)) return 0; @@ -964,7 +947,7 @@ struct dma_pool *dma_pool_create(const char *name, struct device *d, size_t size void dma_pool_destroy(struct dma_pool *d) { - dde_kit_log(DEBUG_DMA, "close"); + lx_log(DEBUG_DMA, "close"); destroy(Genode::env()->heap(), d); } @@ -974,7 +957,7 @@ void *dma_pool_alloc(struct dma_pool *d, gfp_t f, dma_addr_t *dma) void *addr; addr = dma_alloc_coherent(0, d->size, dma, 0); - dde_kit_log(DEBUG_DMA, "addr: %p size %zx align %x phys: %lx pool %p", + lx_log(DEBUG_DMA, "addr: %p size %zx align %x phys: %lx pool %p", addr, d->size, d->align, *dma, d); return addr; } @@ -982,7 +965,7 @@ void *dma_pool_alloc(struct dma_pool *d, gfp_t f, dma_addr_t *dma) void dma_pool_free(struct dma_pool *d, void *vaddr, dma_addr_t a) { - dde_kit_log(DEBUG_DMA, "free: addr %p, size: %zx", vaddr, d->size); + lx_log(DEBUG_DMA, "free: addr %p, size: %zx", vaddr, d->size); Malloc::dma()->free(vaddr); } @@ -994,7 +977,7 @@ void *dma_alloc_coherent(struct device *, size_t size, dma_addr_t *dma, gfp_t) if (!addr) return 0; - dde_kit_log(DEBUG_DMA, "DMA pool alloc addr: %p size %zx align: %d, phys: %lx", + lx_log(DEBUG_DMA, "DMA pool alloc addr: %p size %zx align: %d, phys: %lx", addr, size, PAGE_SHIFT, *dma); return addr; } @@ -1002,7 +985,7 @@ void *dma_alloc_coherent(struct device *, size_t size, dma_addr_t *dma, gfp_t) void dma_free_coherent(struct device *, size_t size, void *vaddr, dma_addr_t) { - dde_kit_log(DEBUG_DMA, "free: addr %p, size: %zx", vaddr, size); + lx_log(DEBUG_DMA, "free: addr %p, size: %zx", vaddr, size); Malloc::dma()->free(vaddr); } @@ -1011,9 +994,6 @@ void dma_free_coherent(struct device *, size_t size, void *vaddr, dma_addr_t) ** linux/dma-mapping.h ** *************************/ -/** - * Translate virt to phys using DDE-kit - */ dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr, size_t size, enum dma_data_direction dir, @@ -1025,7 +1005,7 @@ dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr, PERR("translation virt->phys %p->%lx failed, return ip %p", ptr, phys, __builtin_return_address(0)); - dde_kit_log(DEBUG_DMA, "virt: %p phys: %lx", ptr, phys); + lx_log(DEBUG_DMA, "virt: %p phys: %lx", ptr, phys); return phys; } @@ -1034,7 +1014,7 @@ dma_addr_t dma_map_page(struct device *dev, struct page *page, size_t offset, size_t size, enum dma_data_direction dir) { - dde_kit_log(DEBUG_DMA, "virt: %p phys: %lx offs: %zx", page->virt, page->phys, offset); + lx_log(DEBUG_DMA, "virt: %p phys: %lx offs: %zx", page->virt, page->phys, offset); return page->phys + offset; } @@ -1050,7 +1030,7 @@ int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg, struct task_struct *kthread_run(int (*fn)(void *), void *arg, const char *n, ...) { - dde_kit_log(DEBUG_THREAD, "Run %s", n); + lx_log(DEBUG_THREAD, "Run %s", n); Routine::add(fn, arg, n); return 0; } @@ -1064,7 +1044,7 @@ struct task_struct *kthread_create(int (*threadfn)(void *data), * This is just called for delayed device scanning (see * 'drivers/usb/storage/usb.c') */ - dde_kit_log(DEBUG_THREAD, "Create %s", namefmt); + lx_log(DEBUG_THREAD, "Create %s", namefmt); Routine::add(threadfn, data, namefmt); return 0; } diff --git a/repos/dde_linux/src/lib/usb/main.cc b/repos/dde_linux/src/lib/usb/main.cc index 4f0676170..0e459aae9 100644 --- a/repos/dde_linux/src/lib/usb/main.cc +++ b/repos/dde_linux/src/lib/usb/main.cc @@ -26,10 +26,6 @@ #include #include -extern "C" { -#include -} - using namespace Genode; extern "C" int subsys_usb_init(); @@ -56,9 +52,6 @@ void breakpoint() { PDBG("BREAK"); } static void init(Services *services) { - /* start jiffies */ - dde_kit_timer_init(0, 0); - /* * The RAW driver is initialized first to make sure that it doesn't miss * notifications about added devices. diff --git a/repos/dde_linux/src/lib/usb/nic/nic.cc b/repos/dde_linux/src/lib/usb/nic/nic.cc index 559a814bf..0d0bea8d6 100644 --- a/repos/dde_linux/src/lib/usb/nic/nic.cc +++ b/repos/dde_linux/src/lib/usb/nic/nic.cc @@ -444,7 +444,7 @@ struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev, unsigned int l void dev_kfree_skb(struct sk_buff *skb) { - dde_kit_log(DEBUG_SKB, "free skb: %p start: %p cloned: %d", + lx_log(DEBUG_SKB, "free skb: %p start: %p cloned: %d", skb, skb->start, skb->cloned); if (skb->cloned) { @@ -475,7 +475,7 @@ void skb_reserve(struct sk_buff *skb, int len) return; } skb->data += len; - dde_kit_log(DEBUG_SKB, "skb: %p slen: %u len: %d", skb, skb->len, len); + lx_log(DEBUG_SKB, "skb: %p slen: %u len: %d", skb, skb->len, len); } @@ -493,7 +493,7 @@ unsigned char *skb_push(struct sk_buff *skb, unsigned int len) skb->len += len; skb->data -= len; - dde_kit_log(DEBUG_SKB, "skb: %p slen: %u len: %u", skb, skb->len, len); + lx_log(DEBUG_SKB, "skb: %p slen: %u len: %u", skb, skb->len, len); return skb->data; } @@ -512,7 +512,7 @@ unsigned char *skb_put(struct sk_buff *skb, unsigned int len) unsigned char *old = skb_tail_pointer(skb); skb->len += len; skb->tail += len; - dde_kit_log(DEBUG_SKB, "skb: %p slen: %u len: %u", skb, skb->len, len); + lx_log(DEBUG_SKB, "skb: %p slen: %u len: %u", skb, skb->len, len); return old; } @@ -544,7 +544,7 @@ unsigned char *skb_pull(struct sk_buff *skb, unsigned int len) return 0; } skb->len -= len; - dde_kit_log(DEBUG_SKB, "skb: %p slen: %u len: %u", skb, skb->len, len); + lx_log(DEBUG_SKB, "skb: %p slen: %u len: %u", skb, skb->len, len); return skb->data += len; } @@ -563,7 +563,7 @@ void skb_trim(struct sk_buff *skb, unsigned int len) skb->len = len; skb_set_tail_pointer(skb, len); - dde_kit_log(DEBUG_SKB, "skb: %p slen: %u len: %u", skb, skb->len, len); + lx_log(DEBUG_SKB, "skb: %p slen: %u len: %u", skb, skb->len, len); } diff --git a/repos/dde_linux/src/lib/usb/pci_driver.cc b/repos/dde_linux/src/lib/usb/pci_driver.cc index b954d4c27..e11d827a5 100644 --- a/repos/dde_linux/src/lib/usb/pci_driver.cc +++ b/repos/dde_linux/src/lib/usb/pci_driver.cc @@ -18,8 +18,10 @@ #include /* Genode os includes */ +#include #include #include +#include /* Linux includes */ #include @@ -29,6 +31,68 @@ struct bus_type pci_bus_type; +using namespace Genode; + +class Io_port +{ + + private: + + unsigned _base = 0; + unsigned _size = 0; + Io_port_session_capability _cap; + Lazy_volatile_object _port; + + bool _valid(unsigned port) { + return _cap.valid() && port >= _base && port < _base + _size; } + + public: + + ~Io_port() + { + if (_cap.valid()) + _port.destruct(); + } + + void session(unsigned base, unsigned size, Io_port_session_capability cap) + { + _base = base; + _size = size; + _cap = cap; + _port.construct(_cap); + } + + template + bool out(unsigned port, POD val) + { + if (!_valid(port)) + return false; + + switch (sizeof(POD)) { + case 1: _port->outb(port, val); break; + case 2: _port->outw(port, val); break; + case 4: _port->outl(port, val); break; + } + + return true; + } + + template + bool in(unsigned port, POD *val) + { + if (!_valid(port)) + return false;; + + switch (sizeof(POD)) { + case 1: *val = _port->inb(port); break; + case 2: *val = _port->inw(port); break; + case 4: *val = _port->inl(port); break; + } + + return true; + } +}; + /** * Scan PCI bus and probe for HCDs @@ -40,6 +104,7 @@ class Pci_driver : public Genode::List::Element pci_driver *_drv; /* Linux PCI driver */ Pci::Device_capability _cap; /* PCI cap */ pci_device_id const *_id; /* matched id for this driver */ + Io_port _port; public: @@ -82,7 +147,7 @@ class Pci_driver : public Genode::List::Element /* setup resources */ bool io = false; - for (int i = 0; i < Device::NUM_RESOURCES; i++) { + for (unsigned i = 0; i < Device::NUM_RESOURCES; i++) { Device::Resource res = client.resource(i); _dev->resource[i].start = res.base(); _dev->resource[i].end = res.base() + res.size() - 1; @@ -91,18 +156,16 @@ class Pci_driver : public Genode::List::Element /* request port I/O session */ if (res.type() == Device::Resource::IO) { - if (dde_kit_request_io(res.base(), res.size(), i, bus, dev, - func)) - PERR("Failed to request I/O: [%u,%u)", - res.base(), res.base() + res.size()); + uint8_t virt_bar = client.phys_bar_to_virt(i); + _port.session(res.base(), res.size(), client.io_port(virt_bar)); io = true; - dde_kit_log(DEBUG_PCI, "I/O [%u-%u)", + lx_log(DEBUG_PCI, "I/O [%u-%u)", res.base(), res.base() + res.size()); } /* request I/O memory (write combined) */ if (res.type() == Device::Resource::MEMORY) - dde_kit_log(DEBUG_PCI, "I/O memory [%x-%x)", res.base(), + lx_log(DEBUG_PCI, "I/O memory [%x-%x)", res.base(), res.base() + res.size()); } @@ -166,13 +229,6 @@ class Pci_driver : public Genode::List::Element if (!_dev) return; - for (int i = 0; i < Pci::Device::NUM_RESOURCES; i++) { - resource *r = &_dev->resource[i]; - - if (r->flags & IORESOURCE_IO) - dde_kit_release_io(r->start, (r->end - r->start) + 1); - } - _drivers().remove(this); destroy(Genode::env()->heap(), _dev); @@ -230,6 +286,22 @@ class Pci_driver : public Genode::List::Element PERR("Device using i/o memory of address %zx is unknown", phys); return Genode::Io_mem_session_capability(); } + + template + static POD port_io(unsigned port, POD val = 0) + { + for (Pci_driver *d = _drivers().first(); d; d = d->next()) { + if (!d->_dev) + continue; + + if (READ && d->_port.in(port, &val)) + return val; + else if (!READ && d->_port.out(port, val)) + return (POD)~0; + } + + return (POD)~0; + } }; /******************************** @@ -279,7 +351,7 @@ static Genode::Object_pool memory_pool; int pci_register_driver(struct pci_driver *drv) { - dde_kit_log(DEBUG_PCI, "DRIVER name: %s", drv->name); + lx_log(DEBUG_PCI, "DRIVER name: %s", drv->name); drv->driver.name = drv->name; pci_device_id const *id = drv->id_table; @@ -293,7 +365,7 @@ int pci_register_driver(struct pci_driver *drv) while (id->class_ || id->class_mask || id->class_) { if (id->class_ == (unsigned)PCI_ANY_ID) { - dde_kit_log(DEBUG_PCI, "Skipping PCI_ANY_ID device class"); + lx_log(DEBUG_PCI, "Skipping PCI_ANY_ID device class"); id++; continue; } @@ -308,7 +380,7 @@ int pci_register_driver(struct pci_driver *drv) uint8_t bus, dev, func; Pci::Device_client client(cap); client.bus_address(&bus, &dev, &func); - dde_kit_log(DEBUG_PCI, "bus: %x dev: %x func: %x", bus, dev, func); + lx_log(DEBUG_PCI, "bus: %x dev: %x func: %x", bus, dev, func); } Pci_driver *pci_drv = 0; @@ -378,7 +450,7 @@ int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int, int where, u8 *v { Pci_driver *drv = (Pci_driver *)bus; drv->config_read(where, val); - dde_kit_log(DEBUG_PCI, "READ %p: where: %x val: %x", drv, where, *val); + lx_log(DEBUG_PCI, "READ %p: where: %x val: %x", drv, where, *val); return 0; } @@ -387,7 +459,7 @@ int pci_bus_read_config_word(struct pci_bus *bus, unsigned int, int where, u16 * { Pci_driver *drv = (Pci_driver *)bus; drv->config_read(where, val); - dde_kit_log(DEBUG_PCI, "READ %p: where: %x val: %x", drv, where, *val); + lx_log(DEBUG_PCI, "READ %p: where: %x val: %x", drv, where, *val); return 0; } @@ -395,7 +467,7 @@ int pci_bus_read_config_word(struct pci_bus *bus, unsigned int, int where, u16 * int pci_bus_write_config_word(struct pci_bus *bus, unsigned int, int where, u16 val) { Pci_driver *drv = (Pci_driver *)bus; - dde_kit_log(DEBUG_PCI, "WRITE %p: where: %x val: %x", drv, where, val); + lx_log(DEBUG_PCI, "WRITE %p: where: %x val: %x", drv, where, val); drv->config_write(where, val); return 0; } @@ -404,7 +476,7 @@ int pci_bus_write_config_word(struct pci_bus *bus, unsigned int, int where, u16 int pci_bus_write_config_byte(struct pci_bus *bus, unsigned int, int where, u8 val) { Pci_driver *drv = (Pci_driver *)bus; - dde_kit_log(DEBUG_PCI, "WRITE %p: where: %x val: %x", drv, where, val); + lx_log(DEBUG_PCI, "WRITE %p: where: %x val: %x", drv, where, val); drv->config_write(where, val); return 0; } @@ -462,6 +534,19 @@ void Backend_memory::free(Genode::Ram_dataspace_capability cap) } +/********************** + ** asm-generic/io.h ** + **********************/ + +void outb(u8 value, u32 port) { Pci_driver::port_io(port, value); } +void outw(u16 value, u32 port) { Pci_driver::port_io(port, value); } +void outl(u32 value, u32 port) { Pci_driver::port_io(port, value); } + +u8 inb(u32 port) { return Pci_driver::port_io(port); } +u16 inw(u32 port) { return Pci_driver::port_io(port); } +u32 inl(u32 port) { return Pci_driver::port_io(port); } + + /***************************************** ** Platform specific irq cap discovery ** *****************************************/ diff --git a/repos/dde_linux/src/lib/usb/signal/event.cc b/repos/dde_linux/src/lib/usb/signal/event.cc index 839bb7db1..9aceaba1d 100644 --- a/repos/dde_linux/src/lib/usb/signal/event.cc +++ b/repos/dde_linux/src/lib/usb/signal/event.cc @@ -143,14 +143,14 @@ void __wait_event() void init_completion(struct completion *work) { - dde_kit_log(DEBUG_COMPLETION, "New completion %p", work); + lx_log(DEBUG_COMPLETION, "New completion %p", work); work->done = 0; } void complete(struct completion *work) { - dde_kit_log(DEBUG_COMPLETION, "%p", work); + lx_log(DEBUG_COMPLETION, "%p", work); work->done = 1; /* send signal */ @@ -160,7 +160,7 @@ void complete(struct completion *work) void complete_and_exit(struct completion *work, long code) { - dde_kit_log(DEBUG_COMPLETION, "%p", work); + lx_log(DEBUG_COMPLETION, "%p", work); complete(work); Routine::remove(); } @@ -186,7 +186,7 @@ __wait_completion_timeout(struct completion *work, unsigned long timeout) __wait_event(); if (_j <= jiffies) { - dde_kit_log(1, "Timeout"); + lx_log(1, "Timeout"); return 0; } } @@ -200,14 +200,14 @@ __wait_completion_timeout(struct completion *work, unsigned long timeout) unsigned long wait_for_completion_timeout(struct completion *work, unsigned long timeout) { - dde_kit_log(DEBUG_COMPLETION, "%p state: %u timeout: %lu", work, work->done, timeout); + lx_log(DEBUG_COMPLETION, "%p state: %u timeout: %lu", work, work->done, timeout); return __wait_completion_timeout(work, timeout); } int wait_for_completion_interruptible(struct completion *work) { - dde_kit_log(DEBUG_COMPLETION, "%p state: %u", work, work->done); + lx_log(DEBUG_COMPLETION, "%p state: %u", work, work->done); __wait_completion(work); return 0; @@ -217,7 +217,7 @@ int wait_for_completion_interruptible(struct completion *work) long wait_for_completion_interruptible_timeout(struct completion *work, unsigned long timeout) { - dde_kit_log(DEBUG_COMPLETION, "%p state: %u", work, work->done); + lx_log(DEBUG_COMPLETION, "%p state: %u", work, work->done); __wait_completion(work); return 1; } @@ -225,7 +225,7 @@ long wait_for_completion_interruptible_timeout(struct completion *work, void wait_for_completion(struct completion *work) { - dde_kit_log(DEBUG_COMPLETION, "%p state: %u", work, work->done); + lx_log(DEBUG_COMPLETION, "%p state: %u", work, work->done); __wait_completion(work); } @@ -236,7 +236,7 @@ void wait_for_completion(struct completion *work) signed long schedule_timeout_uninterruptible(signed long timeout) { - dde_kit_log(DEBUG_COMPLETION, "%ld\n", timeout); + lx_log(DEBUG_COMPLETION, "%ld\n", timeout); __wait_event(); return 0; } diff --git a/repos/dde_linux/src/lib/usb/signal/irq.cc b/repos/dde_linux/src/lib/usb/signal/irq.cc index 83211ef29..a9509478a 100644 --- a/repos/dde_linux/src/lib/usb/signal/irq.cc +++ b/repos/dde_linux/src/lib/usb/signal/irq.cc @@ -105,7 +105,7 @@ class Irq_context : public Genode::List::Element /* report IRQ to all clients */ for (Irq_handler *h = _handler_list.first(); h; h = h->next()) if ((handled = _handle_one(h))) { - dde_kit_log(DEBUG_IRQ, "IRQ: %u ret: %u h: %p dev: %p", _irq, handled, h->handler, h->dev); + lx_log(DEBUG_IRQ, "IRQ: %u ret: %u h: %p dev: %p", _irq, handled, h->handler, h->dev); break; } @@ -186,7 +186,7 @@ void Irq::check_irq() int request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char *name, void *dev) { - dde_kit_log(DEBUG_IRQ, "Request irq %u handler %p", irq, handler); + lx_log(DEBUG_IRQ, "Request irq %u handler %p", irq, handler); Irq_context::request_irq(irq, handler, dev); return 0; } diff --git a/repos/dde_linux/src/lib/usb/signal/timer.cc b/repos/dde_linux/src/lib/usb/signal/timer.cc index 907c58dc0..7fa97534a 100644 --- a/repos/dde_linux/src/lib/usb/signal/timer.cc +++ b/repos/dde_linux/src/lib/usb/signal/timer.cc @@ -13,111 +13,325 @@ #include #include +#include +#include +#include #include #include #include + #include "signal.h" +#include "list.h" + +unsigned long jiffies; + static void handler(void *timer); +namespace Lx { + class Timer; +} -/* our local incarnation of sender and receiver */ -static Signal_helper *_signal = 0; - +static int run_timer(void *); /** - * Signal context for time-outs + * Lx::Timer */ -template -class Timer_context +class Lx::Timer { + public: + + /** + * Context encapsulates a regular linux timer_list + */ + struct Context : public Lx::List::Element + { + enum { INVALID_TIMEOUT = ~0UL }; + enum Type { LIST, HR }; + + Type type; + void *timer; + bool pending { false }; + unsigned long timeout { INVALID_TIMEOUT }; /* absolute in jiffies */ + bool programmed { false }; + + Context(struct timer_list *timer) : type(LIST), timer(timer) { } + Context(struct hrtimer *timer) : type(HR), timer(timer) { } + + void expires(unsigned long e) + { + if (type == LIST) + static_cast(timer)->expires = e; + } + + void function() + { + switch (type) { + case LIST: + { + timer_list *t = static_cast(timer); + if (t->function) + t->function(t->data); + } + break; + + case HR: + { + hrtimer *t = static_cast(timer); + if (t->function) + t->function(t); + } + break; + } + } + }; + private: - CLASS *_timer; /* Linux timer */ - dde_kit_timer *_dde_timer; /* DDE kit timer */ - Genode::Signal_rpc_member _dispatcher; - - /* call timer function */ - void _handle(unsigned) { _timer->function(_timer->data); } + ::Timer::Connection _timer_conn; + Lx::List _list; + Routine *_timer_task = Routine::add(run_timer, nullptr, "timer"); + Genode::Signal_rpc_member _dispatcher; + Genode::Tslab _timer_alloc; public: - Timer_context(CLASS *timer) - : _timer(timer), _dde_timer(0), - _dispatcher(_signal->ep(), *this, &Timer_context::_handle) {} + bool ready { true }; - /* schedule next timeout */ - void schedule(unsigned long expires) - { - if (!_dde_timer) - _dde_timer = dde_kit_timer_add(handler, this, expires); - else - dde_kit_timer_schedule_absolute(_dde_timer, expires); - } - - char const *debug() { return "Timer_context"; } + private: /** - * Return true if timer is pending + * Lookup local timer */ - bool pending() const + Context *_find_context(void const *timer) { - return _dde_timer ? dde_kit_timer_pending(_dde_timer) : false; + for (Context *c = _list.first(); c; c = c->next()) + if (c->timer == timer) + return c; + + return 0; } /** - * Return internal signal cap + * Program the first timer in the list + * + * The first timer is programmed if the 'programmed' flag was not set + * before. The second timer is flagged as not programmed as + * 'Timer::trigger_once' invalidates former registered one-shot + * timeouts. */ - Genode::Signal_context_capability cap() const { return _dispatcher; } + void _program_first_timer() + { + Context *ctx = _list.first(); + if (!ctx) + return; + + if (ctx->programmed) + return; + + /* calculate relative microseconds for trigger */ + unsigned long us = ctx->timeout > jiffies ? + jiffies_to_msecs(ctx->timeout - jiffies) * 1000 : 0; + _timer_conn.trigger_once(us); + + ctx->programmed = true; + + /* possibly programmed successor must be reprogrammed later */ + if (Context *next = ctx->next()) + next->programmed = false; + } /** - * Convert 'timer_list' to 'Timer_conext' + * Schedule timer + * + * Add the context to the scheduling list depending on its timeout + * and reprogram the first timer. */ - static Timer_context *to_ctx(CLASS const *timer) { - return static_cast *>(timer->timer); } - - void remove() + void _schedule_timer(Context *ctx, unsigned long expires) { - if (_dde_timer) - dde_kit_timer_del(_dde_timer); + _list.remove(ctx); - _dde_timer = 0; + ctx->timeout = expires; + ctx->pending = true; + ctx->programmed = false; + /* + * Also write the timeout value to the expires field in + * struct timer_list because the checks + * it directly. + */ + ctx->expires(expires); + + Context *c; + for (c = _list.first(); c; c = c->next()) + if (ctx->timeout <= c->timeout) + break; + _list.insert_before(ctx, c); + + _program_first_timer(); } + + /** + * Handle trigger_once signal + */ + void _handle(unsigned) + { + ready = true; + Routine::schedule_all(); + } + + public: + + /** + * Constructor + */ + Timer(Server::Entrypoint &ep) + : + _dispatcher(ep, *this, &Lx::Timer::_handle), + _timer_alloc(Genode::env()->heap()) + { + _timer_conn.sigh(_dispatcher); + } + + /** + * Add new linux timer + */ + template + void add(TIMER *timer) + { + Context *t = new (&_timer_alloc) Context(timer); + _list.append(t); + } + + /** + * Delete linux timer + */ + int del(void *timer) + { + Context *ctx = _find_context(timer); + + /** + * If the timer expired it was already cleaned up after its + * execution. + */ + if (!ctx) + return 0; + + int rv = ctx->timeout != Context::INVALID_TIMEOUT ? 1 : 0; + + _list.remove(ctx); + destroy(&_timer_alloc, ctx); + + return rv; + } + + /** + * Initial scheduling of linux timer + */ + int schedule(void *timer, unsigned long expires) + { + Context *ctx = _find_context(timer); + if (!ctx) { + PERR("schedule unknown timer %p", timer); + return -1; /* XXX better use 0 as rv? */ + } + + /* + * If timer was already active return 1, otherwise 0. The return + * value is needed by mod_timer(). + */ + int rv = ctx->timeout != Context::INVALID_TIMEOUT ? 1 : 0; + + _schedule_timer(ctx, expires); + + return rv; + } + + /** + * Schedule next linux timer + */ + void schedule_next() { _program_first_timer(); } + + /** + * Check if the timer is currently pending + */ + bool pending(void const *timer) + { + Context *ctx = _find_context(timer); + if (!ctx) { + return false; + } + + return ctx->pending; + } + + Context *find(void const *timer) { + return _find_context(timer); } + + /** + * Update jiffie counter + */ + void update_jiffies() + { + jiffies = msecs_to_jiffies(_timer_conn.elapsed_ms()); + } + + /** + * Get first timer context + */ + Context* first() { return _list.first(); } }; -/** - * C handler for DDE timer interface - */ -static void handler(void *timer) -{ - Timer_context *t = static_cast *>(timer); +Genode::Lazy_volatile_object _lx_timer; - /* set context and submit */ - _signal->sender().context(t->cap()); - _signal->sender().submit(); + +void Timer::init(Server::Entrypoint &ep) +{ + _lx_timer.construct(ep); + + /* initialize value explicitly */ + jiffies = 0UL; } +void Timer::update_jiffies() +{ + _lx_timer->update_jiffies(); +} -void Timer::init(Server::Entrypoint &ep) { - _signal = new (Genode::env()->heap()) Signal_helper(ep); } +static int run_timer(void *) +{ + while (1) { + _wait_event(_lx_timer->ready); + + while (Lx::Timer::Context *ctx = _lx_timer->first()) { + if (ctx->timeout > jiffies) + break; + + ctx->function(); + _lx_timer->del(ctx->timer); + } + + _lx_timer->ready = false; + } + + return 0; +} /******************* ** linux/timer.h ** *******************/ -void init_timer(struct timer_list *timer) { - timer->timer = (void *) new (Genode::env()->heap()) Timer_context(timer); } +void init_timer(struct timer_list *timer) { } int mod_timer(struct timer_list *timer, unsigned long expires) { - dde_kit_log(DEBUG_TIMER, "Timer: %p j: %lu ex: %lu func %p", - timer, jiffies, expires, timer->function); - Timer_context::to_ctx(timer)->schedule(expires); - return 0; + if (!_lx_timer->find(timer)) + _lx_timer->add(timer); + + return _lx_timer->schedule(timer, expires); } @@ -126,23 +340,24 @@ void setup_timer(struct timer_list *timer,void (*function)(unsigned long), { timer->function = function; timer->data = data; - init_timer(timer); } int timer_pending(const struct timer_list * timer) { - bool pending = Timer_context::to_ctx(timer)->pending(); - dde_kit_log(DEBUG_TIMER, "Pending %p %u", timer, pending); + bool pending = _lx_timer->pending(timer); + lx_log(DEBUG_TIMER, "Pending %p %u", timer, pending); return pending; } int del_timer(struct timer_list *timer) { - dde_kit_log(DEBUG_TIMER, "Delete timer %p", timer); - Timer_context::to_ctx(timer)->remove(); - return 0; + lx_log(DEBUG_TIMER, "Delete timer %p", timer); + int rv = _lx_timer->del(timer); + _lx_timer->schedule_next(); + + return rv; } @@ -150,25 +365,26 @@ int del_timer(struct timer_list *timer) ** linux/hrtimer.h ** *********************/ -void hrtimer_init(struct hrtimer *timer, clockid_t clock_id, enum hrtimer_mode mode) -{ - timer->timer = (void *) new (Genode::env()->heap()) Timer_context(timer); - timer->data = timer; -} +void hrtimer_init(struct hrtimer *timer, clockid_t clock_id, enum hrtimer_mode mode) { } int hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim, unsigned long delta_ns, const enum hrtimer_mode mode) { - unsigned long expires = tim.tv64 / (NSEC_PER_MSEC * DDE_KIT_HZ); - dde_kit_log(DEBUG_TIMER, "HR: e: %lu j %lu", jiffies, expires); - Timer_context::to_ctx(timer)->schedule(expires); - return 0; + unsigned long expires = tim.tv64 / (NSEC_PER_MSEC * HZ); + + if (!_lx_timer->find(timer)) + _lx_timer->add(timer); + + lx_log(DEBUG_TIMER, "HR: e: %lu j %lu", jiffies, expires); + return _lx_timer->schedule(timer, expires); } int hrtimer_cancel(struct hrtimer *timer) { - Timer_context::to_ctx(timer)->remove(); - return 0; + int rv = _lx_timer->del(timer); + _lx_timer->schedule_next(); + + return rv; } diff --git a/repos/dde_linux/src/lib/usb/storage/scsi.c b/repos/dde_linux/src/lib/usb/storage/scsi.c index a1af6523e..89bbefae7 100644 --- a/repos/dde_linux/src/lib/usb/storage/scsi.c +++ b/repos/dde_linux/src/lib/usb/storage/scsi.c @@ -46,7 +46,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *t, int priv_size) { - dde_kit_log(DEBUG_SCSI, "t=%p, priv_size=%d", t, priv_size); + lx_log(DEBUG_SCSI, "t=%p, priv_size=%d", t, priv_size); static int free = 1; @@ -143,9 +143,9 @@ void _scsi_free_command(struct scsi_cmnd *cmnd) static void inquiry_done(struct scsi_cmnd *cmnd) { char *data = (char *)scsi_buffer_data(cmnd); - dde_kit_printf("Vendor id: %c%c%c%c%c%c%c%c Product id: %s\n", - data[8], data[9], data[10], data[11], data[12], - data[13], data[14], data[15], &data[16]); + lx_printf("Vendor id: %c%c%c%c%c%c%c%c Product id: %s\n", + data[8], data[9], data[10], data[11], data[12], + data[13], data[14], data[15], &data[16]); complete(cmnd->back); }