Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

SmiImpl.h

Go to the documentation of this file.
00001 // vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:
00002 /*
00003  * Copyright (C) 2005 Dell Inc.
00004  *  by Michael Brown <Michael_E_Brown@dell.com>
00005  * Licensed under the Open Software License version 2.1
00006  *
00007  * Alternatively, you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published
00009  * by the Free Software Foundation; either version 2 of the License,
00010  * or (at your option) any later version.
00011  
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00015  * See the GNU General Public License for more details.
00016  */
00017 
00018 #ifndef SMIIMPL_H
00019 #define SMIIMPL_H
00020 
00021 #include "smbios/ISmi.h"
00022 #include "SmiLowLevel.h"
00023 #include "ExceptionImpl.h"
00024 
00025 namespace smi
00026 {
00027     // define our exceptions
00028     DEFINE_EXCEPTION_EX( SmiExceptionImpl, smi, SmiException);
00029     DEFINE_EXCEPTION_EX( InvalidSmiModeImpl, smi, InvalidSmiMode);
00030     DEFINE_EXCEPTION_EX( ParameterErrorImpl, smi, ParameterError);
00031     DEFINE_EXCEPTION_EX( UnsupportedSmiImpl, smi, UnsupportedSmi);
00032     DEFINE_EXCEPTION_EX( UnhandledSmiImpl,   smi, UnhandledSmi);
00033     DEFINE_EXCEPTION_EX( SmiExecutedWithErrorImpl, smi, SmiExecutedWithError);
00034     DEFINE_EXCEPTION_EX( PasswordVerificationFailedImpl, smi, PasswordVerificationFailed);
00035     DEFINE_EXCEPTION_EX( ConfigErrorImpl, smi, ConfigError);
00036 
00037     class SmiStrategy
00038     {
00039     public:
00040         SmiStrategy()
00041         {}
00042         ;
00043         virtual ~SmiStrategy()
00044         {}
00045         ;
00046 
00047         virtual void lock()
00048             = 0;
00049         virtual void setSize(int) = 0;
00050         virtual size_t getPhysicalBufferBaseAddress() = 0;
00051         virtual void addInputBuffer(u8 *buffer, size_t size) = 0;
00052         virtual void execute() = 0;
00053         virtual void getResultBuffer(u8 *buffer, size_t size) = 0;
00054         virtual void finish() = 0;
00055     };
00056 
00057     class SmiMockStrategy : public SmiStrategy
00058     {
00059     public:
00060         SmiMockStrategy(std::string initFilename) : fh(fopen (initFilename.c_str (), "w+b")), filename(initFilename)
00061         {}
00062         ;
00063         virtual ~SmiMockStrategy()
00064         {
00065             fclose (fh);
00066         };
00067 
00068         virtual void lock()
00069         {}
00070         ;
00071         virtual void setSize(int)
00072         {}
00073         ;
00074         virtual size_t getPhysicalBufferBaseAddress()
00075         {
00076             return 0xDEADBEEF;
00077         };
00078         virtual void addInputBuffer(u8 *buffer, size_t size)
00079         {
00080             fwrite(buffer, 1, size, fh);
00081         };
00082         virtual void execute()
00083         {
00084             fseek(fh,0,0);
00085         };
00086         virtual void getResultBuffer(u8 *buffer, size_t size)
00087         {
00088             fread(buffer,1,size,fh);
00089         };
00090         virtual void finish()
00091         {}
00092         ;
00093     private:
00094         FILE *fh;
00095         std::string filename;
00096     };
00097 
00098     class SmiArchStrategy : public SmiStrategy
00099     {
00100     public:
00101         SmiArchStrategy();
00102         virtual ~SmiArchStrategy();
00103 
00104         virtual void lock()
00105             ;
00106         virtual void setSize(int);
00107         virtual size_t getPhysicalBufferBaseAddress();
00108         virtual void addInputBuffer(u8 *buffer, size_t size);
00109         virtual void execute();
00110         virtual void getResultBuffer(u8 *buffer, size_t size);
00111         virtual void finish();
00112 
00113     private:
00114         void *privateData;
00115     };
00116 
00117 
00118     class DellCallingInterfaceSmiImpl : virtual public IDellCallingInterfaceSmi
00119     {
00120     public:
00121         DellCallingInterfaceSmiImpl(SmiStrategy *);
00122         virtual ~DellCallingInterfaceSmiImpl();
00123 
00124         virtual void execute();
00125         virtual void setClass( u16 newClass );
00126         virtual void setSelect( u16 newSelect );
00127         virtual void setArg( u8 argNumber, u32 argValue );
00128         virtual u32  getRes( u8 resNumber ) const;
00129         virtual void setArgAsPhysicalAddress( u8 argNumber, u32 bufferOffset );
00130         virtual u8 *getBufferPtr();
00131         virtual void setBufferSize(size_t newSize);
00132         virtual void setCommandIOMagic( u16 address, u8 code );
00133 
00134     protected:
00135         struct calling_interface_command_buffer smi_buf;
00136         bool argIsAddress[4];
00137         u32  argAddressOffset[4];
00138         struct callintf_cmd                     kernel_buf;
00139         u8                                      *buffer;
00140         size_t                                  bufferSize;
00141         std::auto_ptr<SmiStrategy>              smiStrategy;
00142 
00143 
00144     private:
00145         DellCallingInterfaceSmiImpl();
00146     };
00147 
00148 }
00149 
00150 #endif  /* SMIIMPL_H */

Generated on Wed Apr 11 16:25:10 2007 for SMBIOS Library by doxygen 1.3.5