diff --git a/repos/dde_linux/run/wifi.run b/repos/dde_linux/run/wifi.run index 3f09222d72..20a0169ad8 100644 --- a/repos/dde_linux/run/wifi.run +++ b/repos/dde_linux/run/wifi.run @@ -137,7 +137,7 @@ set firmware_modules { set boot_modules { core ld.lib.so init timer rtc_drv report_rom dynamic_rom vfs_jitterentropy.lib.so - libc.lib.so libcrypto.lib.so libssl.lib.so + libc.lib.so libm.lib.so libcrypto.lib.so libssl.lib.so wpa_driver_nl80211.lib.so wpa_supplicant.lib.so wifi.lib.so wifi_drv diff --git a/repos/dde_linux/src/drivers/framebuffer/intel/include/lx_emul.h b/repos/dde_linux/src/drivers/framebuffer/intel/include/lx_emul.h index b29e3cc5b6..21d2091d0a 100644 --- a/repos/dde_linux/src/drivers/framebuffer/intel/include/lx_emul.h +++ b/repos/dde_linux/src/drivers/framebuffer/intel/include/lx_emul.h @@ -216,12 +216,6 @@ extern struct atomic_notifier_head panic_notifier_list; (void) (&_min1 == &_min2); \ _min1 < _min2 ? _min1 : _min2; }) -#define max(x, y) ({ \ - typeof(x) _max1 = (x); \ - typeof(y) _max2 = (y); \ - (void) (&_max1 == &_max2); \ - _max1 > _max2 ? _max1 : _max2; }) - #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi) /* linux/i2c.h */ diff --git a/repos/dde_linux/src/drivers/framebuffer/intel/lx_emul.cc b/repos/dde_linux/src/drivers/framebuffer/intel/lx_emul.cc index 209bdb5102..78da603d23 100644 --- a/repos/dde_linux/src/drivers/framebuffer/intel/lx_emul.cc +++ b/repos/dde_linux/src/drivers/framebuffer/intel/lx_emul.cc @@ -1021,7 +1021,8 @@ void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size) { enum { VIDEO_ROM_BASE = 0xC0000, VIDEO_ROM_SIZE = 0x20000 }; - static Genode::Attached_io_mem_dataspace vrom(VIDEO_ROM_BASE, VIDEO_ROM_SIZE); + static Genode::Attached_io_mem_dataspace vrom(Lx_kit::env().env(), + VIDEO_ROM_BASE, VIDEO_ROM_SIZE); *size = VIDEO_ROM_SIZE; return vrom.local_addr(); } diff --git a/repos/dde_linux/src/drivers/framebuffer/intel/main.cc b/repos/dde_linux/src/drivers/framebuffer/intel/main.cc index f5f123ad4c..d076a7578b 100644 --- a/repos/dde_linux/src/drivers/framebuffer/intel/main.cc +++ b/repos/dde_linux/src/drivers/framebuffer/intel/main.cc @@ -6,7 +6,7 @@ */ /* - * Copyright (C) 2015 Genode Labs GmbH + * Copyright (C) 2015-2017 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. @@ -17,13 +17,14 @@ #include #include #include -#include /* Server related local includes */ #include /* Linux emulation environment includes */ #include +#include +#include #include #include #include @@ -48,39 +49,51 @@ struct Main Genode::Heap heap { env.ram(), env.rm() }; Framebuffer::Root root { env, heap, config }; - /* init singleton Lx::Timer */ - Lx::Timer &timer = Lx::timer(&ep, &jiffies); - - /* init singleton Lx::Irq */ - Lx::Irq &irq = Lx::Irq::irq(&ep, &heap); - - /* init singleton Lx::Work */ - Lx::Work &work = Lx::Work::work_queue(&heap); - /* Linux task that handles the initialization */ - Lx::Task linux { run_linux, reinterpret_cast(this), "linux", - Lx::Task::PRIORITY_0, Lx::scheduler() }; + Genode::Constructible linux; Main(Genode::Env &env) : env(env) { Genode::log("--- intel framebuffer driver ---"); + Lx_kit::construct_env(env); + + /* init singleton Lx::Scheduler */ + Lx::scheduler(&env); + + Lx::pci_init(env, env.ram(), heap); + Lx::malloc_init(env, heap); + + /* init singleton Lx::Timer */ + Lx::timer(&env, &ep, &heap, &jiffies); + + /* init singleton Lx::Irq */ + Lx::Irq::irq(&ep, &heap); + + /* init singleton Lx::Work */ + Lx::Work::work_queue(&heap); + + linux.construct(run_linux, reinterpret_cast(this), + "linux", Lx::Task::PRIORITY_0, Lx::scheduler()); + /* give all task a first kick before returning */ Lx::scheduler().schedule(); } void announce() { env.parent().announce(ep.manage(root)); } + + Lx::Task &linux_task() { return *linux; } }; struct Policy_agent { Main &main; - Genode::Signal_rpc_member sd; + Genode::Signal_handler sd; - void handle(unsigned) + void handle() { - main.linux.unblock(); + main.linux_task().unblock(); Lx::scheduler().schedule(); } diff --git a/repos/dde_linux/src/drivers/framebuffer/intel/target.mk b/repos/dde_linux/src/drivers/framebuffer/intel/target.mk index 8561229efc..25e146733a 100644 --- a/repos/dde_linux/src/drivers/framebuffer/intel/target.mk +++ b/repos/dde_linux/src/drivers/framebuffer/intel/target.mk @@ -13,7 +13,8 @@ SRC_CC += irq.cc \ printf.cc \ scheduler.cc \ timer.cc \ - work.cc + work.cc \ + env.cc INC_DIR += $(REP_DIR)/src/include diff --git a/repos/dde_linux/src/drivers/wifi/main.cc b/repos/dde_linux/src/drivers/wifi/main.cc index db0b0bbb88..a9c56589b6 100644 --- a/repos/dde_linux/src/drivers/wifi/main.cc +++ b/repos/dde_linux/src/drivers/wifi/main.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -105,7 +105,7 @@ static int generatewpa_supplicant_conf(char const **p, Genode::size_t *len, char struct Wlan_configration { - Genode::Attached_rom_dataspace config_rom { "wlan_configuration" }; + Genode::Attached_rom_dataspace config_rom; Genode::Signal_handler dispatcher; Genode::Lock update_lock; @@ -208,9 +208,10 @@ struct Wlan_configration void _handle_update() { _update_configuration(); } - Wlan_configration(Genode::Entrypoint &ep) + Wlan_configration(Genode::Env &env) : - dispatcher(ep, *this, &Wlan_configration::_handle_update) + config_rom(env, "wlan_configuration"), + dispatcher(env.ep(), *this, &Wlan_configration::_handle_update) { config_rom.sigh(dispatcher); _update_configuration(); @@ -244,7 +245,7 @@ struct Main wpa->start(); try { - wlan_config = new (&heap) Wlan_configration(env.ep()); + wlan_config = new (&heap) Wlan_configration(env); } catch (...) { Genode::warning("could not create Wlan_configration handler"); } diff --git a/repos/dde_linux/src/drivers/wifi/wpa.h b/repos/dde_linux/src/drivers/wifi/wpa.h index 016d56fd7e..174aeb7bd4 100644 --- a/repos/dde_linux/src/drivers/wifi/wpa.h +++ b/repos/dde_linux/src/drivers/wifi/wpa.h @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -19,6 +19,7 @@ /* entry function */ extern "C" int wpa_main(int debug_msg, int connected_scan_interval); +extern "C" void wpa_reporter_init(void *env); extern "C" void wpa_conf_reload(void); class Wpa_thread : public Genode::Thread @@ -38,7 +39,9 @@ class Wpa_thread : public Genode::Thread Thread(env, "wpa_supplicant", 8*1024*sizeof(long)), _lock(lock), _exit(-1), _debug_msg(debug_msg), _connected_scan_interval(connected_scan_interval) - { } + { + wpa_reporter_init(&env); + } void entry() { diff --git a/repos/dde_linux/src/include/lx_emul/impl/completion.h b/repos/dde_linux/src/include/lx_emul/impl/completion.h index bde9b37e86..c9787b7440 100644 --- a/repos/dde_linux/src/include/lx_emul/impl/completion.h +++ b/repos/dde_linux/src/include/lx_emul/impl/completion.h @@ -5,13 +5,14 @@ */ /* - * Copyright (C) 2015-2016 Genode Labs GmbH + * Copyright (C) 2015-2017 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. */ /* Linux kint includes */ +#include #include typedef Lx::Task::List_element Wait_le; @@ -20,25 +21,23 @@ typedef Lx::Task::List Wait_list; void init_waitqueue_head(wait_queue_head_t *wq) { - wq->list = new (Genode::env()->heap()) Wait_list; + wq->list = new (&Lx_kit::env().heap()) Wait_list; } void remove_wait_queue(wait_queue_head_t *wq, wait_queue_t *wait) { Wait_list *list = static_cast(wq->list); - if (!list) - return; + if (!list) { return; } - destroy(Genode::env()->heap(), list); + destroy(&Lx_kit::env().heap(), list); } int waitqueue_active(wait_queue_head_t *wq) { Wait_list *list = static_cast(wq->list); - if (!list) - return 0; + if (!list) { return 0; } return list->first() ? 1 : 0; } @@ -55,8 +54,7 @@ void __wake_up(wait_queue_head_t *wq, bool all) Wait_le *le = list->first(); do { - if (!le) - return; + if (!le) { return; } le->object()->unblock(); } while (all && (le = le->next())); diff --git a/repos/dde_linux/src/include/lx_emul/impl/delay.h b/repos/dde_linux/src/include/lx_emul/impl/delay.h index 02d520bdc2..df3e4d2d97 100644 --- a/repos/dde_linux/src/include/lx_emul/impl/delay.h +++ b/repos/dde_linux/src/include/lx_emul/impl/delay.h @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2015-2016 Genode Labs GmbH + * Copyright (C) 2015-2017 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. @@ -14,21 +14,32 @@ /* Genode includes */ #include +#include #include /* - * XXX We may consider to use the Lx::Timer instead of opening a dedicated - * timer session. + * XXX "We may consider to use the Lx::Timer instead of opening a dedicated + * timer session" which I tried during the deprecation warning removal + * but it did not work out. At least the intel_fb at that point got stuck + * because the workqueue task got mutex blocked. */ -static Timer::Connection _delay_timer; +static Genode::Constructible _delay_timer; +static inline void __delay_timer(unsigned long usecs) +{ + if (!_delay_timer.constructed()) { + _delay_timer.construct(Lx_kit::env().env()); + } -void udelay(unsigned long usecs) { _delay_timer.usleep(usecs); } + _delay_timer->usleep(usecs); +} + +void udelay(unsigned long usecs) { __delay_timer(usecs); } void msleep(unsigned int msecs) { - _delay_timer.msleep(msecs); + __delay_timer(1000 * msecs); Lx::timer_update_jiffies(); } diff --git a/repos/dde_linux/src/include/lx_emul/impl/gfp.h b/repos/dde_linux/src/include/lx_emul/impl/gfp.h index 22f669f609..577b8ada8c 100644 --- a/repos/dde_linux/src/include/lx_emul/impl/gfp.h +++ b/repos/dde_linux/src/include/lx_emul/impl/gfp.h @@ -15,6 +15,7 @@ #include #include #include +#include struct page *alloc_pages(gfp_t gfp_mask, unsigned int order) @@ -24,7 +25,7 @@ struct page *alloc_pages(gfp_t gfp_mask, unsigned int order) size_t size = PAGE_SIZE << order; Genode::Ram_dataspace_capability ds_cap = Lx::backend_alloc(size, Genode::UNCACHED); - page->addr = Genode::env()->rm_session()->attach(ds_cap); + page->addr = Lx_kit::env().rm().attach(ds_cap); page->paddr = Genode::Dataspace_client(ds_cap).phys_addr(); if (!page->addr) { diff --git a/repos/dde_linux/src/include/lx_emul/impl/mutex.h b/repos/dde_linux/src/include/lx_emul/impl/mutex.h index 3255a610d1..d4f1be3395 100644 --- a/repos/dde_linux/src/include/lx_emul/impl/mutex.h +++ b/repos/dde_linux/src/include/lx_emul/impl/mutex.h @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2015-2016 Genode Labs GmbH + * Copyright (C) 2015-2017 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. @@ -13,7 +13,7 @@ /* Linux kit includes */ #include - +#include enum { MUTEX_UNLOCKED = 1, MUTEX_LOCKED = 0, MUTEX_WAITERS = -1 }; @@ -23,7 +23,7 @@ void mutex_init(struct mutex *m) m->state = MUTEX_UNLOCKED; m->holder = nullptr; - m->waiters = new (Genode::env()->heap()) Lx::Task::List; + m->waiters = nullptr; m->id = ++id; m->counter = 0; } @@ -31,9 +31,14 @@ void mutex_init(struct mutex *m) void mutex_destroy(struct mutex *m) { - /* FIXME potentially blocked tasks are not unblocked */ + Lx::Task::List *waiters = static_cast(m->waiters); - Genode::destroy(Genode::env()->heap(), static_cast(m->waiters)); + /* FIXME potentially blocked tasks are not unblocked */ + if (waiters->first()) { + Genode::error(__func__, "destroying non-empty waiters list"); + } + + Genode::destroy(&Lx_kit::env().heap(), waiters); m->holder = nullptr; m->waiters = nullptr; @@ -42,8 +47,18 @@ void mutex_destroy(struct mutex *m) } +static inline void __check_or_initialize_mutex(struct mutex *m) +{ + if (!m->waiters) { + m->waiters = new (&Lx_kit::env().heap()) Lx::Task::List; + } +} + + void mutex_lock(struct mutex *m) { + __check_or_initialize_mutex(m); + while (1) { if (m->state == MUTEX_UNLOCKED) { m->state = MUTEX_LOCKED; diff --git a/repos/dde_linux/src/include/lx_emul/impl/pci.h b/repos/dde_linux/src/include/lx_emul/impl/pci.h index caa184ab33..eaef41fe51 100644 --- a/repos/dde_linux/src/include/lx_emul/impl/pci.h +++ b/repos/dde_linux/src/include/lx_emul/impl/pci.h @@ -5,13 +5,14 @@ */ /* - * Copyright (C) 2015-2016 Genode Labs GmbH + * Copyright (C) 2015-2017 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. */ /* Linux kit includes */ +#include #include #include @@ -49,7 +50,7 @@ extern "C" int pci_register_driver(struct pci_driver *driver) return false; /* create 'pci_dev' struct for matching device */ - pci_dev = new (env()->heap()) Lx::Pci_dev(cap); + pci_dev = new (&Lx_kit::env().heap()) Lx::Pci_dev(cap); /* enable ioremap to work */ Lx::pci_dev_registry()->insert(pci_dev); diff --git a/repos/dde_linux/src/include/lx_kit/irq.h b/repos/dde_linux/src/include/lx_kit/irq.h index 02ccadba26..3d1efbb08d 100644 --- a/repos/dde_linux/src/include/lx_kit/irq.h +++ b/repos/dde_linux/src/include/lx_kit/irq.h @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -17,7 +17,6 @@ #define _LX_KIT__IRQ_H_ /* Genode includes */ -#include #include @@ -27,7 +26,7 @@ class Lx::Irq { public: - static Irq &irq(Server::Entrypoint *ep = nullptr, + static Irq &irq(Genode::Entrypoint *ep = nullptr, Genode::Allocator *alloc = nullptr); /** diff --git a/repos/dde_linux/src/include/lx_kit/malloc.h b/repos/dde_linux/src/include/lx_kit/malloc.h index fc116ceec5..f8bbb8acf2 100644 --- a/repos/dde_linux/src/include/lx_kit/malloc.h +++ b/repos/dde_linux/src/include/lx_kit/malloc.h @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -25,6 +25,8 @@ namespace Lx { class Malloc; + + void malloc_init(Genode::Env &env, Genode::Allocator &md_alloc); } diff --git a/repos/dde_linux/src/include/lx_kit/pci.h b/repos/dde_linux/src/include/lx_kit/pci.h new file mode 100644 index 0000000000..0e541285c8 --- /dev/null +++ b/repos/dde_linux/src/include/lx_kit/pci.h @@ -0,0 +1,26 @@ +/* + * \brief PCI backend + * \author Josef Soentgen + * \date 2017-02-12 + */ + +/* + * Copyright (C) 2017 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 _LX_KIT__PCI_H_ +#define _LX_KIT__PCI_H_ + +/* Genode includes */ +#include + + +namespace Lx { + + void pci_init(Genode::Env&, Genode::Ram_session&, Genode::Allocator&); +} + +#endif /* _LX_KIT__PCI_H_ */ diff --git a/repos/dde_linux/src/include/lx_kit/pci_dev_registry.h b/repos/dde_linux/src/include/lx_kit/pci_dev_registry.h index 66fe97e240..24432c6b75 100644 --- a/repos/dde_linux/src/include/lx_kit/pci_dev_registry.h +++ b/repos/dde_linux/src/include/lx_kit/pci_dev_registry.h @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2015 Genode Labs GmbH + * Copyright (C) 2015-2017 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. @@ -15,6 +15,7 @@ #define _LX_KIT__PCI_DEV_REGISTRY_H_ /* Linux emulation environment includes */ +#include #include namespace Lx { diff --git a/repos/dde_linux/src/include/lx_kit/scheduler.h b/repos/dde_linux/src/include/lx_kit/scheduler.h index 79aa2cdabb..4cd794d8eb 100644 --- a/repos/dde_linux/src/include/lx_kit/scheduler.h +++ b/repos/dde_linux/src/include/lx_kit/scheduler.h @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -16,6 +16,9 @@ #ifndef _LX_KIT__SCHEDULER_H_ #define _LX_KIT__SCHEDULER_H_ +/* Genode includes */ +#include + namespace Lx { class Task; @@ -26,7 +29,7 @@ namespace Lx { * * Implementation must be provided by the driver. */ - Scheduler &scheduler(); + Scheduler &scheduler(Genode::Env *env = nullptr); } diff --git a/repos/dde_linux/src/include/lx_kit/timer.h b/repos/dde_linux/src/include/lx_kit/timer.h index ae82bdb297..af164f6bf8 100644 --- a/repos/dde_linux/src/include/lx_kit/timer.h +++ b/repos/dde_linux/src/include/lx_kit/timer.h @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -17,7 +17,7 @@ #define _LX_KIT__TIMER_H_ /* Genode includes */ -#include +#include namespace Lx { @@ -32,7 +32,9 @@ namespace Lx { * \param jiffies_ptr pointer to jiffies counter to be periodically * updated */ - Timer &timer(Server::Entrypoint *ep = nullptr, + Timer &timer(Genode::Env *env = nullptr, + Genode::Entrypoint *ep = nullptr, + Genode::Allocator *md_alloc = nullptr, unsigned long *jiffies_ptr = nullptr); void timer_update_jiffies(); @@ -47,6 +49,7 @@ class Lx::Timer public: enum Type { LIST, HR }; + /** * Add new linux timer */ @@ -81,6 +84,11 @@ class Lx::Timer * Update jiffie counter */ virtual void update_jiffies() = 0; + + /** + * Suspend calling thread + */ + virtual void usleep(unsigned us) = 0; }; diff --git a/repos/dde_linux/src/lib/libnl/lxcc_emul.cc b/repos/dde_linux/src/lib/libnl/lxcc_emul.cc index 22a4d4fbe5..1fc6742258 100644 --- a/repos/dde_linux/src/lib/libnl/lxcc_emul.cc +++ b/repos/dde_linux/src/lib/libnl/lxcc_emul.cc @@ -5,13 +5,13 @@ */ /* - * Copyright (C) 2014 Genode Labs GmbH + * Copyright (C) 2014-2017 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. */ -/* Genode */ +/* Genode includes */ #include #include @@ -33,323 +33,3 @@ extern "C" char *getenv(const char *name) return nullptr; } - - -#if 0 -#include -#include -#include -#include -#include -#include -#include - -#include - - -extern "C" { - -/************* - ** errno.h ** - *************/ - -int errno; - - -/************* - ** stdio.h ** - *************/ - -FILE *stdout; -FILE *stderr; - - -void *malloc(size_t size) -{ - /* align on pointer size */ - size = size + ((sizeof(Genode::addr_t)-1) & ~(sizeof(Genode::addr_t)-1)); - - size_t rsize = size + sizeof (Genode::addr_t); - - void *addr = 0; - if (!Genode::env()->heap()->alloc(size, &addr)) - return 0; - - *(Genode::addr_t*)addr = rsize; - return ((Genode::addr_t*)addr) + 1; -} - - -void *calloc(size_t nmemb, size_t size) -{ -#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) - if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && - nmemb > 0 && SIZE_MAX / nmemb < size) { - return NULL; - } - - size *= nmemb; - - void *addr = malloc(size); - Genode::memset(addr, 0, size); - return addr; -} - - -void free(void *ptr) -{ - if (!ptr) - return; - - Genode::addr_t *addr = ((Genode::addr_t*)ptr) - 1; - Genode::env()->heap()->free(addr, *addr); -} - -void *realloc(void *ptr, Genode::size_t size) -{ - if (!size) - free(ptr); - - void *n = malloc(size); - size_t s = *((size_t *)ptr - 1); - - Genode::memcpy(n, ptr, Genode::min(s, size)); - - free(ptr); - - return n; -} - - -/************** - ** stdlib.h ** - **************/ - -static char getenv_HZ[] = "100"; -static char getenv_TICKS_PER_USEC[] = "10000"; - -char *getenv(const char *name) -{ - /* these values must match the ones of lx_emul wifi */ - - if (Genode::strcmp(name, "HZ") == 0) return getenv_HZ; - if (Genode::strcmp(name, "TICKS_PER_USEC") == 0) return getenv_TICKS_PER_USEC; - - return nullptr; -} - - -long int strtol(const char *nptr, char **endptr, int base) -{ - long res = 0; - if (base != 0 && base != 10) { - Genode::error("strtol: base of ", base, " is not supported"); - return 0; - } - Genode::ascii_to(nptr, res); - return res; -} - - -double strtod(const char *nptr, char **endptr) -{ - double res = 0; - Genode::ascii_to(nptr, res); - return res; -} - - -/******************** - ** linux/string.h ** - ********************/ - -size_t strcspn(const char *s, const char *reject) -{ - for (char const *p = s; *p; p++) { - char c = *p; - - for (char const *r = reject; *r; r++) { - char d = *r; - if (c == d) - return (p - 1 - s); - } - } - return 0; -} - - -char *strdup(const char *s) -{ - size_t len = strlen(s); - - char *p = (char *) malloc(len + 1); - - return strncpy(p, s, len + 1); -} - - -size_t strlen(const char *s) -{ - return Genode::strlen(s); -} - - -int strcasecmp(const char* s1, const char *s2) -{ - return Genode::strcmp(s1, s2); -} - - -int strcmp(const char* s1, const char *s2) -{ - return Genode::strcmp(s1, s2); -} - - -int strncmp(const char *s1, const char *s2, size_t len) -{ - return Genode::strcmp(s1, s2, len); -} - - -char *strchr(const char *p, int ch) -{ - char c; - c = ch; - for (;; ++p) { - if (*p == c) - return ((char *)p); - if (*p == '\0') - break; - } - - return 0; -} - - -void *memchr(const void *s, int c, size_t n) -{ - const unsigned char *p = reinterpret_cast(s); - while (n-- != 0) { - if ((unsigned char)c == *p++) { - return (void *)(p - 1); - } - } - return NULL; -} - - -char *strnchr(const char *p, size_t count, int ch) -{ - char c; - c = ch; - for (; count; ++p, count--) { - if (*p == c) - return ((char *)p); - if (*p == '\0') - break; - } - - return 0; -} - - -char *strncat(char *dst, const char *src, size_t n) -{ - char *p = dst; - while (*p++) ; - - while ((*p = *src) && (n-- > 0)) { - ++src; - ++p; - } - - return dst; -} - - -char *strcpy(char *dst, const char *src) -{ - char *p = dst; - - while ((*dst = *src)) { - ++src; - ++dst; - } - - return p; -} - - -char *strncpy(char *dst, const char* src, size_t n) -{ - return Genode::strncpy(dst, src, n); -} - - -int snprintf(char *str, size_t size, const char *format, ...) -{ - va_list list; - - va_start(list, format); - Genode::String_console sc(str, size); - sc.vprintf(format, list); - va_end(list); - - return sc.len(); -} - - -int vsnprintf(char *str, size_t size, const char *format, va_list args) -{ - Genode::String_console sc(str, size); - sc.vprintf(format, args); - - return sc.len(); -} - - -int asprintf(char **strp, const char *fmt, ...) -{ - /* XXX for now, let's hope strings are not getting longer than 256 bytes */ - enum { MAX_STRING_LENGTH = 256 }; - char *p = (char*)malloc(MAX_STRING_LENGTH); - if (!p) - return -1; - - va_list args; - - va_start(args, fmt); - Genode::String_console sc(p, MAX_STRING_LENGTH); - sc.vprintf(fmt, args); - va_end(args); - - return strlen(p); -} - - -/************** - ** unistd.h ** - **************/ - -int getpagesize(void) { - return 4096; } - - -pid_t getpid(void) { - return 42; } - - -/************ - ** time.h ** - ************/ - -extern unsigned long jiffies; - -time_t time(time_t *t) -{ - return jiffies; -} - -} /* extern "C" */ -#endif diff --git a/repos/dde_linux/src/lib/libnl/socket.cc b/repos/dde_linux/src/lib/libnl/socket.cc index 1ee306ee92..022f0a4bb3 100644 --- a/repos/dde_linux/src/lib/libnl/socket.cc +++ b/repos/dde_linux/src/lib/libnl/socket.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -61,12 +61,10 @@ using namespace Wifi; extern Socket_call socket_call; -struct Socket_fd : public Genode::List::Element +struct Socket_fd { Socket *s; int fd; - - Socket_fd(Socket *s, int fd) : s(s), fd(fd) { } }; @@ -75,47 +73,77 @@ class Socket_registry private : /* abritary value (it goes to eleven!) */ - enum { SOCKETS_INITIAL_VALUE = 11, }; + enum { + SOCKETS_INITIAL_VALUE = 11, + MAX_SOCKETS = 7, + }; + static Socket_fd _socket_fd[MAX_SOCKETS]; static unsigned _sockets; - static Genode::List *_list() /* XXX ptr array instead of list? */ + template + static void _for_each_socket_fd(FUNC const & func) { - static Genode::List _l; - return &_l; + for (int i = 0; i < MAX_SOCKETS; i++) { + if (func(_socket_fd[i])) { break; } + } } public: static int insert(Socket *s) { - Socket_fd *sfd = new (Genode::env()->heap()) Socket_fd(s, ++_sockets); + int fd = -1; - _list()->insert(sfd); + auto lambda = [&] (Socket_fd &sfd) { + if (sfd.s != nullptr) { return false; } - return sfd->fd; + sfd.s = s; + sfd.fd = ++_sockets; + + /* return fd */ + fd = sfd.fd; + return true; + }; + + _for_each_socket_fd(lambda); + + return fd; } static void remove(Socket *s) { - for (Socket_fd *sfd = _list()->first(); sfd; sfd = sfd->next()) - if (sfd->s == s) { - _list()->remove(sfd); - destroy(Genode::env()->heap(), sfd); - break; - } + auto lambda = [&] (Socket_fd &sfd) { + if (sfd.s != s) { return false; } + + sfd.s = nullptr; + sfd.fd = 0; + + return true; + }; + + _for_each_socket_fd(lambda); } static Socket *find(int fd) { - for (Socket_fd *sfd = _list()->first(); sfd; sfd = sfd->next()) - if (sfd->fd == fd) - return sfd->s; + Socket *s = nullptr; - return 0; + auto lambda = [&] (Socket_fd &sfd) { + if (sfd.fd != fd) { return false; } + + /* return socket */ + s = sfd.s; + return true; + }; + + _for_each_socket_fd(lambda); + + return s; } }; +Socket_fd Socket_registry::_socket_fd[MAX_SOCKETS] = {}; unsigned Socket_registry::_sockets = Socket_registry::SOCKETS_INITIAL_VALUE; diff --git a/repos/dde_linux/src/lib/lxip/socket_handler.cc b/repos/dde_linux/src/lib/lxip/socket_handler.cc index 5b40205966..eef113a655 100644 --- a/repos/dde_linux/src/lib/lxip/socket_handler.cc +++ b/repos/dde_linux/src/lib/lxip/socket_handler.cc @@ -24,6 +24,7 @@ /* Lx_kit */ #include +#include static const bool verbose = false; @@ -627,10 +628,11 @@ Lxip::Socketcall & Lxip::init(Genode::Env &env, static Net::Socketcall socketcall(env); + Lx::lxcc_emul_init(lx_env); + Lx::malloc_init(env, lx_env.heap()); Lx::timer_init(env, socketcall, lx_env.heap(), ticker); Lx::event_init(env, socketcall, ticker); Lx::nic_client_init(env, socketcall, lx_env.heap(), ticker); - Lx::lxcc_emul_init(lx_env); lxip_init(); diff --git a/repos/dde_linux/src/lib/usb/include/platform.h b/repos/dde_linux/src/lib/usb/include/platform.h index 1d03eb84a7..957aabe63c 100644 --- a/repos/dde_linux/src/lib/usb/include/platform.h +++ b/repos/dde_linux/src/lib/usb/include/platform.h @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2012-2013 Genode Labs GmbH + * Copyright (C) 2012-2017 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. @@ -18,7 +18,6 @@ #include #include -#include #include #include @@ -122,6 +121,8 @@ struct Services } }; +void backend_alloc_init(Genode::Env &env, Genode::Ram_session &ram, Genode::Allocator &alloc); + void platform_hcd_init(Services *services); Genode::Irq_session_capability platform_irq_activate(int irq); diff --git a/repos/dde_linux/src/lib/usb/include/spec/arm/platform_device/platform_device.h b/repos/dde_linux/src/lib/usb/include/spec/arm/platform_device/platform_device.h index 39210e30e6..455bb75a62 100644 --- a/repos/dde_linux/src/lib/usb/include/spec/arm/platform_device/platform_device.h +++ b/repos/dde_linux/src/lib/usb/include/spec/arm/platform_device/platform_device.h @@ -8,7 +8,7 @@ */ /* - * Copyright (C) 2016 Genode Labs GmbH + * Copyright (C) 2016-2017 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. @@ -34,17 +34,19 @@ namespace Platform { struct Device; } struct Platform::Device : Platform::Abstract_device, Genode::List::Element { + Genode::Env &env; + unsigned irq_num; Genode::Constructible irq_connection; - Device(unsigned irq) : irq_num(irq) { } + Device(Genode::Env &env, unsigned irq) : env(env), irq_num(irq) { } unsigned vendor_id() { return ~0U; } unsigned device_id() { return ~0U; } Genode::Irq_session_capability irq(Genode::uint8_t) override { - irq_connection.construct(irq_num); + irq_connection.construct(env, irq_num); return irq_connection->cap(); } @@ -62,14 +64,14 @@ struct Platform::Device : Platform::Abstract_device, Genode::List::Eleme return l; } - static Device &create(unsigned irq_num) + static Device &create(Genode::Env &env, unsigned irq_num) { Device *d; for (d = list().first(); d; d = d->next()) if (d->irq_num == irq_num) return *d; - d = new (Lx::Malloc::mem()) Device(irq_num); + d = new (Lx::Malloc::mem()) Device(env, irq_num); list().insert(d); return *d; diff --git a/repos/dde_linux/src/lib/usb/input/input_component.cc b/repos/dde_linux/src/lib/usb/input/input_component.cc index 054bf8888b..78cb1d9254 100644 --- a/repos/dde_linux/src/lib/usb/input/input_component.cc +++ b/repos/dde_linux/src/lib/usb/input/input_component.cc @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2011-2013 Genode Labs GmbH + * Copyright (C) 2011-2017 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. @@ -26,27 +26,15 @@ using namespace Genode; /** - * Return singleton instance of input-session component + * Singleton instance of input-session component */ -static Input::Session_component &input_session() -{ - static Input::Session_component inst; - return inst; -} +static Genode::Constructible _input_session; /** - * Return singleton instance of input-root component - * - * On the first call (from 'start_input_service'), the 'ep' argument is - * specified. All subsequent calls (from 'input_callback') just return the - * reference to the singleton instance. + * Singleton instance of input-root component */ -static Input::Root_component &input_root(Rpc_entrypoint *ep = 0) -{ - static Input::Root_component root(*ep, input_session()); - return root; -} +static Genode::Constructible _input_root; /** @@ -66,7 +54,7 @@ static void input_callback(enum input_event_type type, case EVENT_TYPE_TOUCH: t = Input::Event::TOUCH; break; } - input_session().submit(Input::Event(t, code, + _input_session->submit(Input::Event(t, code, absolute_x, absolute_y, relative_x, relative_y)); } @@ -78,7 +66,10 @@ void start_input_service(void *ep_ptr, void * service_ptr) Services *service = static_cast(service_ptr); Env &env = service->env; - env.parent().announce(ep->manage(&input_root(ep))); + _input_session.construct(env, env.ram()); + _input_root.construct(*ep, *_input_session); + + env.parent().announce(ep->manage(&*_input_root)); genode_input_register(input_callback, service->screen_width, service->screen_height, service->multitouch); diff --git a/repos/dde_linux/src/lib/usb/lx_emul.cc b/repos/dde_linux/src/lib/usb/lx_emul.cc index 7ed5877f7d..66aab84fae 100644 --- a/repos/dde_linux/src/lib/usb/lx_emul.cc +++ b/repos/dde_linux/src/lib/usb/lx_emul.cc @@ -6,7 +6,7 @@ */ /* - * Copyright (C) 2012-2013 Genode Labs GmbH + * Copyright (C) 2012-2017 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. @@ -43,7 +43,7 @@ void backtrace() { } void pci_dev_put(struct pci_dev *pci_dev) { - Genode::destroy(Genode::env()->heap(), pci_dev); + Genode::destroy(&Lx_kit::env().heap(), pci_dev); } /*********************** diff --git a/repos/dde_linux/src/lib/usb/main.cc b/repos/dde_linux/src/lib/usb/main.cc index 605e9b9805..3e7ce3d902 100644 --- a/repos/dde_linux/src/lib/usb/main.cc +++ b/repos/dde_linux/src/lib/usb/main.cc @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2012-2014 Genode Labs GmbH + * Copyright (C) 2012-2017 Genode Labs GmbH * Copyright (C) 2014 Ksys Labs LLC * * This file is part of the Genode OS framework, which is distributed @@ -17,7 +17,6 @@ /* Genode */ #include -#include #include /* Local */ @@ -25,6 +24,7 @@ #include #include +#include #include #include #include @@ -107,6 +107,12 @@ void start_usb_driver(Genode::Env &env) { /* initialize USB env */ Lx_kit::construct_env(env); + + /* sets up backend alloc needed by malloc */ + backend_alloc_init(env, env.ram(), Lx_kit::env().heap()); + + Lx::malloc_init(env, Lx_kit::env().heap()); + static Services services(env); if (services.hid) @@ -118,8 +124,8 @@ void start_usb_driver(Genode::Env &env) if (services.raw) Raw::init(env, services.raw_report_device_list); - Lx::Scheduler &sched = Lx::scheduler(); - Lx::Timer &timer = Lx::timer(&env.ep(), &jiffies); + Lx::Scheduler &sched = Lx::scheduler(&env); + Lx::Timer &timer = Lx::timer(&env, &env.ep(), &Lx_kit::env().heap(), &jiffies); Lx::Irq::irq(&env.ep(), &Lx_kit::env().heap()); Lx::Work::work_queue(&Lx_kit::env().heap()); diff --git a/repos/dde_linux/src/lib/usb/nic/nic.cc b/repos/dde_linux/src/lib/usb/nic/nic.cc index 41abfb0c25..8b44e49d30 100644 --- a/repos/dde_linux/src/lib/usb/nic/nic.cc +++ b/repos/dde_linux/src/lib/usb/nic/nic.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2012-2013 Genode Labs GmbH + * Copyright (C) 2012-2017 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. @@ -14,7 +14,6 @@ #include #include #include -#include #include #include diff --git a/repos/dde_linux/src/lib/usb/spec/arm/platform_generic.cc b/repos/dde_linux/src/lib/usb/spec/arm/platform_generic.cc index ff7ee192db..052ff48bff 100644 --- a/repos/dde_linux/src/lib/usb/spec/arm/platform_generic.cc +++ b/repos/dde_linux/src/lib/usb/spec/arm/platform_generic.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2016 Genode Labs GmbH + * Copyright (C) 2016-2017 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. @@ -22,6 +22,13 @@ ** lx_kit/backend_alloc.h ** ****************************/ +void backend_alloc_init(Genode::Env&, Genode::Ram_session&, + Genode::Allocator&) +{ + /* intentionally left blank */ +} + + Genode::Ram_dataspace_capability Lx::backend_alloc(Genode::addr_t size, Genode::Cache_attribute cached) { return Lx_kit::env().env().ram().alloc(size, cached); } @@ -38,7 +45,7 @@ void Lx::backend_free(Genode::Ram_dataspace_capability cap) { extern "C" int request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char *name, void *dev) { - Lx::Irq::irq().request_irq(Platform::Device::create(irq), handler, dev); + Lx::Irq::irq().request_irq(Platform::Device::create(Lx_kit::env().env(), irq), handler, dev); return 0; } diff --git a/repos/dde_linux/src/lib/usb/spec/x86/pci_driver.cc b/repos/dde_linux/src/lib/usb/spec/x86/pci_driver.cc index bf6f099fcc..af3e8477ac 100644 --- a/repos/dde_linux/src/lib/usb/spec/x86/pci_driver.cc +++ b/repos/dde_linux/src/lib/usb/spec/x86/pci_driver.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2016 Genode Labs GmbH + * Copyright (C) 2016-2017 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. @@ -194,3 +194,14 @@ int request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, return -ENODEV; } + + +/********************************* + ** Platform backend alloc init ** + *********************************/ + +void backend_alloc_init(Genode::Env &env, Genode::Ram_session &ram, + Genode::Allocator &alloc) +{ + Lx::pci_init(env, ram, alloc); +} diff --git a/repos/dde_linux/src/lib/usb/spec/x86/platform.cc b/repos/dde_linux/src/lib/usb/spec/x86/platform.cc index 73139dee5c..0370bbf978 100644 --- a/repos/dde_linux/src/lib/usb/spec/x86/platform.cc +++ b/repos/dde_linux/src/lib/usb/spec/x86/platform.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2013 Genode Labs GmbH + * Copyright (C) 2013-2017 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. @@ -43,7 +43,3 @@ void platform_hcd_init(Services *s) if (s->uhci) module_uhci_hcd_init(); } - - - - diff --git a/repos/dde_linux/src/lib/usb/storage/storage.cc b/repos/dde_linux/src/lib/usb/storage/storage.cc index f6a3ffd93f..2f3ddb29a9 100644 --- a/repos/dde_linux/src/lib/usb/storage/storage.cc +++ b/repos/dde_linux/src/lib/usb/storage/storage.cc @@ -14,7 +14,6 @@ #include #include #include -#include #include #include diff --git a/repos/dde_linux/src/lib/wifi/init.cc b/repos/dde_linux/src/lib/wifi/init.cc index 7991de5fe7..3080a767de 100644 --- a/repos/dde_linux/src/lib/wifi/init.cc +++ b/repos/dde_linux/src/lib/wifi/init.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -21,10 +21,12 @@ #include +#include #include #include #include #include +#include extern "C" void core_netlink_proto_init(void); @@ -142,9 +144,9 @@ void wifi_init(Genode::Env &env, Genode::Lock &lock, bool disable_11n) /* add init_net namespace to namespace list */ list_add_tail_rcu(&init_net.list, &net_namespace_list); - Lx::scheduler(); + Lx::scheduler(&env); - Lx::timer(&env.ep(), &jiffies); + Lx::timer(&env, &env.ep(), &Lx_kit::env().heap(), &jiffies); Lx::Irq::irq(&env.ep(), &Lx_kit::env().heap()); Lx::Work::work_queue(&Lx_kit::env().heap()); @@ -152,6 +154,9 @@ void wifi_init(Genode::Env &env, Genode::Lock &lock, bool disable_11n) Lx::socket_init(env.ep(), Lx_kit::env().heap()); Lx::nic_init(env, Lx_kit::env().heap()); + Lx::pci_init(env, env.ram(), Lx_kit::env().heap()); + Lx::malloc_init(env, Lx_kit::env().heap()); + /* set IWL_DISABLE_HT_ALL if disable 11n is requested */ if (disable_11n) { Genode::log("Disable 11n mode"); diff --git a/repos/dde_linux/src/lib/wifi/lx.h b/repos/dde_linux/src/lib/wifi/lx.h index 30fc3e7558..722e84d464 100644 --- a/repos/dde_linux/src/lib/wifi/lx.h +++ b/repos/dde_linux/src/lib/wifi/lx.h @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -14,9 +14,6 @@ #ifndef _LX_H_ #define _LX_H_ -/* Genode includes */ -#include - /* local includes */ #include diff --git a/repos/dde_linux/src/lib/wifi/lxcc_emul.cc b/repos/dde_linux/src/lib/wifi/lxcc_emul.cc index 415b4b8c12..07979670be 100644 --- a/repos/dde_linux/src/lib/wifi/lxcc_emul.cc +++ b/repos/dde_linux/src/lib/wifi/lxcc_emul.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -723,7 +723,7 @@ int request_firmware_nowait(struct module *module, bool uevent, char const *fw_name = fwl->available_name ? fwl->available_name : fwl->requested_name; - Genode::Rom_connection rom(fw_name); + Genode::Rom_connection rom(Lx_kit::env().env(), fw_name); Genode::Dataspace_capability ds_cap = rom.dataspace(); if (!ds_cap.valid()) { @@ -1225,7 +1225,7 @@ int request_module(char const* format, ...) * XXX We have to create the waiters list lazy because the way * DEFINE_MUTEX is currently implemented does not work w/o * a global Env that was constructed before the static ctors - * are called. + * are called */ static inline void __check_or_initialize_mutex(struct mutex *m) { diff --git a/repos/dde_linux/src/lib/wifi/nic.cc b/repos/dde_linux/src/lib/wifi/nic.cc index 1151cd2f40..d3a070d346 100644 --- a/repos/dde_linux/src/lib/wifi/nic.cc +++ b/repos/dde_linux/src/lib/wifi/nic.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -93,7 +92,7 @@ class Wifi_session_component : public Nic::Session_component Genode::Allocator &rx_block_md_alloc, Genode::Ram_session &ram_session, Genode::Region_map ®ion_map, - Server::Entrypoint &ep, net_device *ndev) + Genode::Entrypoint &ep, net_device *ndev) : Session_component(tx_buf_size, rx_buf_size, rx_block_md_alloc, ram_session, region_map, ep), _ndev(ndev) diff --git a/repos/dde_linux/src/lib/wifi/socket_call.cc b/repos/dde_linux/src/lib/wifi/socket_call.cc index ab2c732d22..ef4d46ba1e 100644 --- a/repos/dde_linux/src/lib/wifi/socket_call.cc +++ b/repos/dde_linux/src/lib/wifi/socket_call.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -128,8 +128,8 @@ class Lx::Socket Genode::Signal_transmitter _sender; - Genode::Signal_rpc_member _dispatcher; - Lx::Task _task; + Genode::Signal_handler _dispatcher; + Lx::Task _task; struct socket *_call_socket() { @@ -326,7 +326,7 @@ class Lx::Socket _call.handle->non_block = _call.non_block.value; } - void _handle(unsigned) + void _handle() { _task.unblock(); Lx::scheduler().schedule(); diff --git a/repos/dde_linux/src/lib/wpa_supplicant/reporter.cc b/repos/dde_linux/src/lib/wpa_supplicant/reporter.cc index 035c46413b..c9e6f8daa5 100644 --- a/repos/dde_linux/src/lib/wpa_supplicant/reporter.cc +++ b/repos/dde_linux/src/lib/wpa_supplicant/reporter.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -29,8 +29,18 @@ extern "C" { } -static Genode::Reporter accesspoints_reporter = { "wlan_accesspoints" }; -static Genode::Reporter state_reporter = { "wlan_state" }; +static Genode::Constructible accesspoints_reporter; +static Genode::Constructible state_reporter; + + +extern "C" void wpa_reporter_init(void *env) +{ + accesspoints_reporter.construct(*static_cast(env), "wlan_accesspoints"); + accesspoints_reporter->enabled(true); + + state_reporter.construct(*static_cast(env), "wlan_state"); + state_reporter->enabled(true); +} enum { SSID_MAX_LEN = 32 + 1, MAC_STR_LEN = 6*2 + 5 + 1}; @@ -45,10 +55,8 @@ static inline void mac2str(char *buf, u8 const *mac) extern "C" void wpa_report_connect_event(struct wpa_supplicant *wpa_s) { - state_reporter.enabled(true); - try { - Genode::Reporter::Xml_generator xml(state_reporter, [&]() { + Genode::Reporter::Xml_generator xml(*state_reporter, [&]() { struct wpa_ssid *wpa_ssid = wpa_s->current_ssid; /* FIXME ssid may contain any characters, even NUL */ @@ -70,10 +78,8 @@ extern "C" void wpa_report_connect_event(struct wpa_supplicant *wpa_s) extern "C" void wpa_report_disconnect_event(struct wpa_supplicant *wpa_s) { - state_reporter.enabled(true); - try { - Genode::Reporter::Xml_generator xml(state_reporter, [&]() { + Genode::Reporter::Xml_generator xml(*state_reporter, [&]() { struct wpa_ssid *wpa_ssid = wpa_s->current_ssid; /* FIXME ssid may contain any characters, even NUL */ @@ -113,10 +119,8 @@ static inline int approximate_quality(struct wpa_bss *bss) extern "C" void wpa_report_scan_results(struct wpa_supplicant *wpa_s) { - accesspoints_reporter.enabled(true); - try { - Genode::Reporter::Xml_generator xml(accesspoints_reporter, [&]() { + Genode::Reporter::Xml_generator xml(*accesspoints_reporter, [&]() { for (unsigned i = 0; i < wpa_s->last_scan_res_used; i++) { struct wpa_bss *bss = wpa_s->last_scan_res[i]; diff --git a/repos/dde_linux/src/lib/wpa_supplicant/symbol.map b/repos/dde_linux/src/lib/wpa_supplicant/symbol.map index 5240f28157..01695c3d2c 100644 --- a/repos/dde_linux/src/lib/wpa_supplicant/symbol.map +++ b/repos/dde_linux/src/lib/wpa_supplicant/symbol.map @@ -6,6 +6,7 @@ /* needed by wifi_drv */ wpa_main; + wpa_reporter_init; /* needed by wpa_driver_nl80211 */ __hide_aliasing_typecast; diff --git a/repos/dde_linux/src/lx_kit/irq.cc b/repos/dde_linux/src/lx_kit/irq.cc index 9aa5cc1ddd..8a184fe614 100644 --- a/repos/dde_linux/src/lx_kit/irq.cc +++ b/repos/dde_linux/src/lx_kit/irq.cc @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -113,7 +113,7 @@ class Lx_kit::Irq : public Lx::Irq /** * Constructor */ - Context(Server::Entrypoint &ep, + Context(Genode::Entrypoint &ep, Platform::Device &dev) : _name(dev), @@ -166,7 +166,7 @@ class Lx_kit::Irq : public Lx::Irq using Context_slab = Genode::Tslab; using Handler_slab = Genode::Tslab; - Server::Entrypoint &_ep; + Genode::Entrypoint &_ep; Lx_kit::List _list; Context_slab _context_alloc; Handler_slab _handler_alloc; @@ -181,14 +181,14 @@ class Lx_kit::Irq : public Lx::Irq return nullptr; } - Irq(Server::Entrypoint &ep, Genode::Allocator &alloc) + Irq(Genode::Entrypoint &ep, Genode::Allocator &alloc) : _ep(ep), _context_alloc(&alloc), _handler_alloc(&alloc) { } public: - static Irq &irq(Server::Entrypoint &ep, Genode::Allocator &alloc) + static Irq &irq(Genode::Entrypoint &ep, Genode::Allocator &alloc) { static Irq inst(ep, alloc); return inst; @@ -227,5 +227,5 @@ class Lx_kit::Irq : public Lx::Irq ** Lx::Irq implementation ** ****************************/ -Lx::Irq &Lx::Irq::irq(Server::Entrypoint *ep, Genode::Allocator *alloc) { +Lx::Irq &Lx::Irq::irq(Genode::Entrypoint *ep, Genode::Allocator *alloc) { return Lx_kit::Irq::irq(*ep, *alloc); } diff --git a/repos/dde_linux/src/lx_kit/malloc.cc b/repos/dde_linux/src/lx_kit/malloc.cc index c985f79bb3..90459f23c3 100644 --- a/repos/dde_linux/src/lx_kit/malloc.cc +++ b/repos/dde_linux/src/lx_kit/malloc.cc @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -80,26 +80,17 @@ class Lx_kit::Slab_backend_alloc : public Lx::Slab_backend_alloc, public: - Slab_backend_alloc(Genode::Cache_attribute cached) + Slab_backend_alloc(Genode::Env &env, Genode::Allocator &md_alloc, + Genode::Cache_attribute cached) : + Rm_connection(env), Region_map_client(Rm_connection::create(VM_SIZE)), - _cached(cached), _index(0), _range(Genode::env()->heap()) + _cached(cached), _index(0), _range(&md_alloc) { /* reserver attach us, anywere */ - _base = Genode::env()->rm_session()->attach(dataspace()); + _base = env.rm().attach(dataspace()); } - static Slab_backend_alloc &mem() - { - static Lx_kit::Slab_backend_alloc inst(Genode::CACHED); - return inst; - } - - static Slab_backend_alloc &dma() - { - static Lx_kit::Slab_backend_alloc inst(Genode::UNCACHED); - return inst; - } /************************************** ** Lx::Slab_backend_alloc interface ** @@ -177,11 +168,11 @@ class Lx_kit::Malloc : public Lx::Malloc typedef Lx::Slab_alloc Slab_alloc; typedef Lx::Slab_backend_alloc Slab_backend_alloc; - Slab_backend_alloc &_back_allocator; - Slab_alloc *_allocator[NUM_SLABS]; - Genode::Cache_attribute _cached; /* cached or un-cached memory */ - addr_t _start; /* VM region of this allocator */ - addr_t _end; + Slab_backend_alloc &_back_allocator; + Genode::Constructible _allocator[NUM_SLABS]; + Genode::Cache_attribute _cached; /* cached or un-cached memory */ + addr_t _start; /* VM region of this allocator */ + addr_t _end; /** * Set 'value' at 'addr' @@ -233,21 +224,9 @@ class Lx_kit::Malloc : public Lx::Malloc { /* init slab allocators */ for (unsigned i = SLAB_START_LOG2; i <= SLAB_STOP_LOG2; i++) - _allocator[i - SLAB_START_LOG2] = new (Genode::env()->heap()) - Slab_alloc(1U << i, alloc); + _allocator[i - SLAB_START_LOG2].construct(1U << i, alloc); } - static Malloc & mem() - { - static Malloc inst(Slab_backend_alloc::mem(), Genode::CACHED); - return inst; - } - - static Malloc & dma() - { - static Malloc inst(Slab_backend_alloc::dma(), Genode::UNCACHED); - return inst; - } /************************** ** Lx::Malloc interface ** @@ -333,7 +312,6 @@ class Lx_kit::Malloc : public Lx::Malloc _back_allocator.free(ptr); } - size_t size(void const *a) { using namespace Genode; @@ -357,29 +335,42 @@ class Lx_kit::Malloc : public Lx::Malloc ** Lx::Malloc implementation ** *******************************/ +static Genode::Constructible _mem_backend_alloc; +static Genode::Constructible _dma_backend_alloc; +static Genode::Constructible _mem_alloc; +static Genode::Constructible _dma_alloc; + + +void Lx::malloc_init(Genode::Env &env, Genode::Allocator &md_alloc) +{ + _mem_backend_alloc.construct(env, md_alloc, Genode::CACHED); + _dma_backend_alloc.construct(env, md_alloc, Genode::UNCACHED); + + _mem_alloc.construct(*_mem_backend_alloc, Genode::CACHED); + _dma_alloc.construct(*_dma_backend_alloc, Genode::UNCACHED); +} + + /** * Cached memory backend allocator */ Lx::Slab_backend_alloc &Lx::Slab_backend_alloc::mem() { - return Lx_kit::Slab_backend_alloc::mem(); } + return *_mem_backend_alloc; } /** * DMA memory backend allocator */ Lx::Slab_backend_alloc &Lx::Slab_backend_alloc::dma() { - return Lx_kit::Slab_backend_alloc::dma(); } + return *_dma_backend_alloc; } /** * Cached memory allocator */ -Lx::Malloc &Lx::Malloc::mem() { - return Lx_kit::Malloc::mem(); } +Lx::Malloc &Lx::Malloc::mem() { return *_mem_alloc; } /** * DMA memory allocator */ -Lx::Malloc &Lx::Malloc::dma() { - return Lx_kit::Malloc::dma(); } - +Lx::Malloc &Lx::Malloc::dma() { return *_dma_alloc; } diff --git a/repos/dde_linux/src/lx_kit/mapped_io_mem_range.cc b/repos/dde_linux/src/lx_kit/mapped_io_mem_range.cc index 699161fead..5712ebd4e4 100644 --- a/repos/dde_linux/src/lx_kit/mapped_io_mem_range.cc +++ b/repos/dde_linux/src/lx_kit/mapped_io_mem_range.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2015-2016 Genode Labs GmbH + * Copyright (C) 2015-2017 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. @@ -21,6 +21,7 @@ #include /* Linux emulation environment includes */ +#include #include #include #include @@ -34,8 +35,7 @@ namespace Lx_kit { class Mapped_io_mem_range; } * * This class is supposed to be a private utility to support 'ioremap'. */ -class Lx_kit::Mapped_io_mem_range : public Lx_kit::List::Element, - public Genode::Rm_connection +class Lx_kit::Mapped_io_mem_range : public Lx_kit::List::Element { private: @@ -47,15 +47,20 @@ class Lx_kit::Mapped_io_mem_range : public Lx_kit::List::El public: - Mapped_io_mem_range(Genode::addr_t phys, Genode::size_t size, + Mapped_io_mem_range(Genode::Env &env, + Genode::Rm_connection &rm, + Genode::addr_t phys, Genode::size_t size, Genode::Io_mem_dataspace_capability ds_cap, Genode::addr_t offset) - : _size(size), - _phys(phys), - _region_map(Rm_connection::create(size)), - _ds(_region_map.dataspace()), - _virt((Genode::addr_t)_ds.local_addr() | (phys &0xfffUL)) { - _region_map.attach_at(ds_cap, 0, size, offset); } + : + _size(size), + _phys(phys), + _region_map(rm.create(size)), + _ds(env.rm(), _region_map.dataspace()), + _virt((Genode::addr_t)_ds.local_addr() | (phys &0xfffUL)) + { + _region_map.attach_at(ds_cap, 0, size, offset); + } Genode::addr_t phys() const { return _phys; } Genode::addr_t virt() const { return _virt; } @@ -82,9 +87,12 @@ class Lx_kit::Mapped_io_mem_range : public Lx_kit::List::El static Lx_kit::List ranges; -/******************************************** +/************************************************ ** Lx_kit::Mapped_io_mem_range implementation ** - ********************************************/ + ************************************************/ + +static Genode::Constructible _global_rm; + void *Lx::ioremap(addr_t phys_addr, unsigned long size, Genode::Cache_attribute cache_attribute) @@ -113,9 +121,23 @@ void *Lx::ioremap(addr_t phys_addr, unsigned long size, return nullptr; } - Lx_kit::Mapped_io_mem_range *io_mem = - new (env()->heap()) Lx_kit::Mapped_io_mem_range(phys_addr, size, - ds_cap, offset); + if (!_global_rm.constructed()) { + _global_rm.construct(Lx_kit::env().env()); + } + + Lx_kit::Mapped_io_mem_range *io_mem = nullptr; + + retry( + [&] () { + io_mem = new (&Lx_kit::env().heap()) + Lx_kit::Mapped_io_mem_range(Lx_kit::env().env(), *_global_rm, + phys_addr, size, ds_cap, offset); + }, + [&] () { + _global_rm->upgrade_ram(16384); + }, + 10 + ); ranges.insert(io_mem); @@ -134,7 +156,7 @@ void Lx::iounmap(volatile void * virt) if (r->virt() == (addr_t)virt) { ranges.remove(r); - destroy(env()->heap(), r); + destroy(&Lx_kit::env().heap(), r); return; } } diff --git a/repos/dde_linux/src/lx_kit/pci.cc b/repos/dde_linux/src/lx_kit/pci.cc index 68d3ac1e2f..3f69ebff72 100644 --- a/repos/dde_linux/src/lx_kit/pci.cc +++ b/repos/dde_linux/src/lx_kit/pci.cc @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -53,22 +53,59 @@ struct Lx_kit::Memory_object_base : Genode::Object_pool::Ent struct Lx_kit::Ram_object : Memory_object_base { - Ram_object(Genode::Ram_dataspace_capability cap) - : Memory_object_base(cap) {} + Genode::Ram_session &_ram; - void free() { Genode::env()->ram_session()->free(ram_cap()); } + Ram_object(Genode::Ram_session &ram, + Genode::Ram_dataspace_capability cap) + : Memory_object_base(cap), _ram(ram) {} + + void free() { _ram.free(ram_cap()); } }; struct Lx_kit::Dma_object : Memory_object_base { - Dma_object(Genode::Ram_dataspace_capability cap) - : Memory_object_base(cap) {} + Platform::Connection &_pci; - void free() { Lx::pci()->free_dma_buffer(ram_cap()); } + Dma_object(Platform::Connection &pci, + Genode::Ram_dataspace_capability cap) + : Memory_object_base(cap), _pci(pci) {} + + void free() { _pci.free_dma_buffer(ram_cap()); } }; +/******************** + ** Pci singletons ** + ********************/ + +static Genode::Constructible _global_pci; +static Genode::Allocator *_global_md_alloc; +static Genode::Ram_session *_global_ram; + + +void Lx::pci_init(Genode::Env &env, Genode::Ram_session &ram, + Genode::Allocator &md_alloc) +{ + _global_pci.construct(env); + _global_ram = &ram; + _global_md_alloc = &md_alloc; +} + + +Platform::Connection *Lx::pci() +{ + return &*_global_pci; +} + + +Lx::Pci_dev_registry *Lx::pci_dev_registry() +{ + static Lx::Pci_dev_registry _pci_dev_registry; + return &_pci_dev_registry; +} + + /********************************* ** Lx::Backend_alloc interface ** *********************************/ @@ -79,24 +116,24 @@ Lx::backend_alloc(Genode::addr_t size, Genode::Cache_attribute cached) using namespace Genode; using namespace Lx_kit; - Memory_object_base *o; + Memory_object_base *obj; Genode::Ram_dataspace_capability cap; if (cached == CACHED) { - cap = env()->ram_session()->alloc(size); - o = new (env()->heap()) Ram_object(cap); + cap = _global_ram->alloc(size); + obj = new (_global_md_alloc) Ram_object(*_global_ram, cap); } else { Genode::size_t donate = size; cap = retry( - [&] () { return Lx::pci()->alloc_dma_buffer(size); }, + [&] () { return _global_pci->alloc_dma_buffer(size); }, [&] () { - Lx::pci()->upgrade_ram(donate); + _global_pci->upgrade_ram(donate); donate = donate * 2 > size ? 4096 : donate * 2; }); - o = new (env()->heap()) Dma_object(cap); + obj = new (_global_md_alloc) Dma_object(*_global_pci, cap); } - memory_pool.insert(o); + memory_pool.insert(obj); return cap; } @@ -107,31 +144,12 @@ void Lx::backend_free(Genode::Ram_dataspace_capability cap) using namespace Lx_kit; Memory_object_base *object; - memory_pool.apply(cap, [&] (Memory_object_base *o) { - object = o; - if (!object) - return; + memory_pool.apply(cap, [&] (Memory_object_base *obj) { + object = obj; + if (!object) { return; } object->free(); memory_pool.remove(object); }); - destroy(env()->heap(), object); -} - - -/******************** - ** Pci singletons ** - ********************/ - -Platform::Connection *Lx::pci() -{ - static Platform::Connection _pci; - return &_pci; -} - - -Lx::Pci_dev_registry *Lx::pci_dev_registry() -{ - static Lx::Pci_dev_registry _pci_dev_registry; - return &_pci_dev_registry; + destroy(_global_md_alloc, object); } diff --git a/repos/dde_linux/src/lx_kit/scheduler.cc b/repos/dde_linux/src/lx_kit/scheduler.cc index 86fa5def6b..5937a02427 100644 --- a/repos/dde_linux/src/lx_kit/scheduler.cc +++ b/repos/dde_linux/src/lx_kit/scheduler.cc @@ -7,7 +7,7 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. @@ -67,16 +67,18 @@ class Lx_kit::Scheduler : public Lx::Scheduler return _ansi_esc_black(); } - struct Logger : Genode::Thread_deprecated<0x4000> + struct Logger : Genode::Thread { Timer::Connection _timer; Lx::Scheduler &_scheduler; unsigned const _interval; - Logger(Lx::Scheduler &scheduler, unsigned interval_seconds) + Logger(Genode::Env &env, Lx::Scheduler &scheduler, + unsigned interval_seconds) : - Genode::Thread_deprecated<0x4000>("logger"), - _scheduler(scheduler), _interval(interval_seconds) + Genode::Thread(env, "logger", 0x4000), + _timer(env), _scheduler(scheduler), + _interval(interval_seconds) { start(); } @@ -91,12 +93,13 @@ class Lx_kit::Scheduler : public Lx::Scheduler } }; + Genode::Constructible _logger; + public: - Scheduler() + Scheduler(Genode::Env &env) { - if (verbose) - new (Genode::env()->heap()) Logger(*this, 10); + if (verbose) { _logger.construct(env, *this, 10); } } /***************************** @@ -220,8 +223,8 @@ Lx::Task::~Task() ** Lx::Scheduler implementation ** **********************************/ -Lx::Scheduler &Lx::scheduler() +Lx::Scheduler &Lx::scheduler(Genode::Env *env) { - static Lx_kit::Scheduler inst; + static Lx_kit::Scheduler inst { *env }; return inst; } diff --git a/repos/dde_linux/src/lx_kit/timer.cc b/repos/dde_linux/src/lx_kit/timer.cc index 7ac6058dea..d64b7b6eef 100644 --- a/repos/dde_linux/src/lx_kit/timer.cc +++ b/repos/dde_linux/src/lx_kit/timer.cc @@ -7,14 +7,13 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2017 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. */ /* Genode includes */ -#include #include #include @@ -84,7 +83,7 @@ class Lx_kit::Timer : public Lx::Timer ::Timer::Connection _timer_conn; Lx_kit::List _list; Lx::Task _timer_task; - Genode::Signal_rpc_member _dispatcher; + Genode::Signal_handler _dispatcher; Genode::Tslab _timer_alloc; Lx::jiffies_update_func _jiffies_func = nullptr; @@ -161,7 +160,7 @@ class Lx_kit::Timer : public Lx::Timer /** * Handle trigger_once signal */ - void _handle(unsigned) + void _handle() { _timer_task.unblock(); @@ -173,13 +172,15 @@ class Lx_kit::Timer : public Lx::Timer /** * Constructor */ - Timer(Server::Entrypoint &ep, unsigned long &jiffies) + Timer(Genode::Env &env, Genode::Entrypoint &ep, + Genode::Allocator &alloc, unsigned long &jiffies) : _jiffies(jiffies), + _timer_conn(env), _timer_task(Timer::run_timer, reinterpret_cast(this), "timer", Lx::Task::PRIORITY_2, Lx::scheduler()), _dispatcher(ep, *this, &Lx_kit::Timer::_handle), - _timer_alloc(Genode::env()->heap()) + _timer_alloc(&alloc) { _timer_conn.sigh(_dispatcher); } @@ -215,6 +216,7 @@ class Lx_kit::Timer : public Lx::Timer /************************* ** Lx::Timer interface ** *************************/ + void add(void *timer, Type type) { Context *t = nullptr; @@ -294,6 +296,9 @@ class Lx_kit::Timer : public Lx::Timer void register_jiffies_func(Lx::jiffies_update_func func) { _jiffies_func = func; } + + void usleep(unsigned us) { + _timer_conn.usleep(us); } }; @@ -301,9 +306,11 @@ class Lx_kit::Timer : public Lx::Timer ** Lx::Timer implementation ** ******************************/ -Lx::Timer &Lx::timer(Server::Entrypoint *ep, unsigned long *jiffies) +Lx::Timer &Lx::timer(Genode::Env *env, Genode::Entrypoint *ep, + Genode::Allocator *md_alloc, + unsigned long *jiffies) { - static Lx_kit::Timer inst(*ep, *jiffies); + static Lx_kit::Timer inst(*env, *ep, *md_alloc, *jiffies); return inst; }