Overview   API Reference  

machine_base.hpp

00001 #if !defined(__MACHINE_BASE_HPP__)
00002 #define __MACHINE_BASE_HPP__
00003 
00004 //
00005 // local includes
00006 //
00007 #include "core/machine/generic/device_container.hpp"
00008 #include "core/machine/devices/device.hpp"
00009 #include "core/machine/iospace/iospace_manager.hpp"
00010 #include "core/machine/memory/memory_manager.hpp"
00011 #include "core/machine/irqs/irq_manager.hpp"
00012 #include "core/machine/pci/pci_bridge_base.hpp"
00013 #include "host_resource_owner.hpp"
00014 
00015 //
00016 // forward declarations
00017 //
00018 struct config_node;
00019 
00025 struct machine_base : public iospace_manager, public memory_manager, public irq_manager
00026 {
00027     static const bool VERBOSE_HOST_RESOURCES = true;
00028     static const int  NO_DEVICE_FOUND        = 0xffff;
00029 
00030   protected:
00035     machine_config config;
00036 
00041     device_container<device> legacy_devices;
00042 
00047     host_resource_owner host_owner;
00048 
00049   public:
00050     machine_base(const l4_threadid_t client=l4_myself())
00051         : iospace_manager(config), memory_manager(config), irq_manager(config), config(client)
00052     {
00053         log::info("initializing virtual machine for task 0x%02x ...\n", config.client.id.task);
00054     }
00055 
00056     virtual ~machine_base(void)
00057     {
00058       #if L4VMM_BUILD_DEBUG
00059         // see whether all destructors were called
00060         print_machine_state(true);
00061       #endif
00062     }
00063 
00064     //
00065     // functions for this class's users:
00066     //     machine init functions
00067     //
00068     virtual int init_machine(const machine_config &config, config_node *config_tree=nullptr);
00069     virtual int reset(void);
00070 
00071     //
00072     // functions for this class's users:
00073     //     set emulation mode & get PCI device functions
00074     //
00075     virtual inline int set_emulation_mode(l4vmm_emulation_modes mode)
00076     {
00077         config.mode=mode;
00078         return 0;
00079     }
00080 
00081     virtual inline pci_device *get_pci_device(pci_devfn devfn)
00082     {
00083         return get_host_bridge().get_device(devfn);
00084     }
00085 
00086     //
00087     // functions for devices referencing their machine object:
00088     //     obtain machine configuration & machine init functions
00089     //
00090     inline const machine_config &get_config(void) const
00091     {
00092         return config;
00093     }
00094 
00095     virtual int request_host_resources(const resource_descriptor &resource,
00096                                        bool verbose=VERBOSE_HOST_RESOURCES);
00097     virtual int request_host_resources(config_node &host_node,
00098                                        bool verbose=VERBOSE_HOST_RESOURCES);
00099 
00100     //
00101     // debug stuff
00102     //
00103     virtual void print_legacy_devices(const char *header=nullptr);
00104     virtual void print_pci_devices(const char *header=nullptr);
00105     virtual void print_machine_state(bool in_destruction=false);
00106 
00107   protected:
00108     //
00109     // functions for this class's users:
00110     //     abstract interface to be implemented in derived classes
00111     //
00112     virtual const char *name(void) const = 0;
00113     virtual pci_bridge &get_host_bridge(void) = 0;
00114 
00115     //
00116     // internal machine init node name to request function mapping
00117     //
00118     static const struct host_option
00119     {
00120         typedef int (machine_base::*request_func_ptr)(config_node &, bool);
00121         const char *name;
00122         request_func_ptr request_func;
00123     } host_options[];
00124 
00125     //
00126     // internal machine init functions
00127     //
00128     virtual int set_option(config_node &option_node);
00129     virtual int create_device(config_node &device_node);
00130     virtual int parse_machine_section(config_node &machine_node);
00131 
00132     virtual int request_host_ports(config_node &port_node, bool verbose=VERBOSE_HOST_RESOURCES);
00133     virtual int request_host_memory(config_node &memory_node, bool verbose=VERBOSE_HOST_RESOURCES);
00134     virtual int request_host_irqs(config_node &irq_node, bool verbose=VERBOSE_HOST_RESOURCES);
00135     virtual int request_host_groups(config_node &group_node, bool verbose=VERBOSE_HOST_RESOURCES);
00136     virtual int request_host_list(config_node &list_node, host_option::request_func_ptr request_func,
00137                                   bool verbose=VERBOSE_HOST_RESOURCES);
00138 
00139   private:
00140     //
00141     // internal create device implementation
00142     //
00143     template <typename DeviceT, typename ContainerT>
00144     int create_device(ContainerT &container, config_node &device_node);
00145 };
00146 
00147 #endif
00148 
00149 // ***** end of source ***** //
00150 

L4vmm Reference Manual, written by Mario Schwalbe  © 2006-2008