From b272a9736ebc6bae0b9d2b5d2054515820cfc114 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Mon, 6 Apr 2009 23:09:58 +0200 Subject: [PATCH] temporary driver registering system --- resources/pci.h => manes/driver.h | 56 +++++++++++++++------------------------ manes/manager.cpp | 16 +++++++++++ manes/manager.h | 7 +++++ manes/manec.h | 13 +++++++++ manes/rtti.cpp | 2 ++ manes/typeinfo | 5 ++++ resources/pci.h | 2 +- 7 files changed, 65 insertions(+), 36 deletions(-) copy resources/pci.h => manes/driver.h (56%) diff --git a/resources/pci.h b/manes/driver.h similarity index 56% copy from resources/pci.h copy to manes/driver.h index e058389..f28e479 100644 --- a/resources/pci.h +++ b/manes/driver.h @@ -1,6 +1,6 @@ -/* Quarn OS +/* Quarn OS / Manes * - * PCI bus + * Type class * * Copyright (C) 2008-2009 Pawel Dziepak * @@ -20,46 +20,32 @@ * */ -#include "bus.h" -#include "arch/low/pci.h" -#include "did.h" -namespace resources { - class pci : public bus { - private: - int dev_count; +#ifndef _DRIVER_H_ +#define _DRIVER_H_ - static const struct vendors_name { - u16 id; - const char *name; - } vendors[]; +#include "type.h" - protected: - u32 get_pci_name(arch::pci_address); +namespace resources { + class did; +} - int scan_bus(); +namespace manes { + class driver : public type { + protected: + delegate recognize_device; public: - bool initialize(); - bool type_added(manes::type_name); - - int get_count(); + driver(const root_type a, const type_name b, const type_name c, + const delegate d, const delegate e) : + type(a, b, c, d), recognize_device(e) {} - string get_name(arch::pci_address); + virtual ~driver() {} - static void register_type(); - }; - - class pci_did : public did { - public: - int irq; - int ioport; - int dma_channel; - void *memory_base; - int bus, device, function; - - pci_did(bus *b) : did(b) {} - pci_did() {} - virtual ~pci_did() {} + virtual bool check_device(resources::did *id) { + return recognize_device(id); + } }; } + +#endif diff --git a/manes/manager.cpp b/manes/manager.cpp index 3a66a48..bddad65 100644 --- a/manes/manager.cpp +++ b/manes/manager.cpp @@ -25,6 +25,7 @@ #include "type.h" #include "component_name.h" #include "type_name.h" +#include "driver.h" #include "error.h" #include "arch/low/irq.h" using namespace manes; @@ -98,6 +99,11 @@ void manager::register_type(const char *me,const char*parent,type::root_type tpe register_type(new type(tpe, (type_name)parent, bus_name, *deleg)); } +void manager::register_driver(const char *me,const char*parent,type::root_type tpe, delegate *deleg, delegate check) { + type_name bus_name(me, true); + register_type(new driver(tpe, (type_name)parent, bus_name, *deleg, check)); +} + void manager::register_type(type *tpe) { assert("manager: incorrect type pointer", tpe == 0); @@ -114,6 +120,16 @@ type *manager::get_type(type_name tpe) const { return (type*)0; } +type *manager::get_driver(resources::did *id) const { + for (int i = 0; i < types.get_count(); i++) + if (types[i]->get_root_type() == type::device && ((driver*)types[i])->check_device(id)) + return types[i]; + + debug("manager: attempt to get not existing driver"); + + return (type*)0; +} + services::kernel_state *manager::get_state() const { return manec::state(); } diff --git a/manes/manager.h b/manes/manager.h index 65f4f77..cc5feb2 100644 --- a/manes/manager.h +++ b/manes/manager.h @@ -31,6 +31,10 @@ namespace services { class kernel_state; } +namespace resources { + class did; +} + namespace manes { class type; @@ -90,6 +94,7 @@ namespace manes { T *get(const string &path); virtual void register_type(const char*,const char*,type::root_type, delegate*); + virtual void register_driver(const char*, const char*, type::root_type, delegate*, delegate); /** * @brief Register new type in Manes. @@ -111,6 +116,8 @@ namespace manes { */ virtual type *get_type(type_name name) const; + virtual type *get_driver(resources::did *) const; + virtual services::kernel_state *get_state() const; virtual arch::irq_op *get_low(); diff --git a/manes/manec.h b/manes/manec.h index 2fda707..b83cedc 100644 --- a/manes/manec.h +++ b/manes/manec.h @@ -26,6 +26,10 @@ #include "manager.h" #include "services/kernel_state.h" +namespace resources { + class did; +} + namespace manes { class error; @@ -51,6 +55,9 @@ namespace manes { template static void register_type(const char*, const char*, type::root_type); + + template + static void register_driver(const char*, const char*, type::root_type, delegate); }; template @@ -70,6 +77,12 @@ void manec::register_type(const char *me, const char *parent, type::root_type tp manec::get()->register_type(new type(tpe, (type_name)parent, bus_name, *bus_create));*/ } +template +void manec::register_driver(const char *me, const char *parent, type::root_type tpe, delegate check) { + delegate *bus_create = new delegate; + bus_create->function(create_object); + manec::get()->register_driver(me, parent, tpe, bus_create, check); +} template T *component::get() const { diff --git a/manes/rtti.cpp b/manes/rtti.cpp index f29ce98..dd59dab 100644 --- a/manes/rtti.cpp +++ b/manes/rtti.cpp @@ -53,6 +53,8 @@ bool __cxxabiv1::__pbase_type_info::__is_pointer_p() const { __cxxabiv1::__pointer_type_info::~__pointer_type_info() {} +__cxxabiv1::__vmi_class_type_info::~__vmi_class_type_info() {} + std::type_info::~type_info() {} bool std::type_info::__is_pointer_p() const { diff --git a/manes/typeinfo b/manes/typeinfo index 58233a8..740763f 100644 --- a/manes/typeinfo +++ b/manes/typeinfo @@ -109,6 +109,11 @@ namespace __cxxabiv1 { public: virtual ~__pointer_type_info(); }; + + class __vmi_class_type_info : public std::type_info { + public: + virtual ~__vmi_class_type_info(); + }; } #endif diff --git a/resources/pci.h b/resources/pci.h index e058389..353674e 100644 --- a/resources/pci.h +++ b/resources/pci.h @@ -56,7 +56,7 @@ namespace resources { int ioport; int dma_channel; void *memory_base; - int bus, device, function; + int ibus, device, function; pci_did(bus *b) : did(b) {} pci_did() {} -- 2.11.4.GIT