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 "../common/ExceptionImpl.h"
00024 
00025 namespace smi
00026 {
00027     // define our exceptions
00028     DEFINE_EXCEPTION_EX( InvalidSmiModeImpl, smi, InvalidSmiMode);
00029     DEFINE_EXCEPTION_EX( ParameterErrorImpl, smi, ParameterError);
00030     DEFINE_EXCEPTION_EX( UnsupportedSmiImpl, smi, UnsupportedSmi);
00031     DEFINE_EXCEPTION_EX( UnhandledSmiImpl,   smi, UnhandledSmi);
00032     DEFINE_EXCEPTION_EX( SmiExecutedWithErrorImpl, smi, SmiExecutedWithError);
00033     DEFINE_EXCEPTION_EX( PasswordVerificationFailedImpl, smi, PasswordVerificationFailed);
00034 
00035     class SmiStrategy
00036     {
00037     public:
00038         SmiStrategy()
00039         {}
00040         ;
00041         virtual ~SmiStrategy()
00042         {}
00043         ;
00044 
00045         virtual void lock()
00046             = 0;
00047         virtual void setSize(int) = 0;
00048         virtual size_t getPhysicalBufferBaseAddress() = 0;
00049         virtual void addInputBuffer(u8 *buffer, size_t size) = 0;
00050         virtual void execute() = 0;
00051         virtual void getResultBuffer(u8 *buffer, size_t size) = 0;
00052         virtual void finish() = 0;
00053     };
00054 
00055     class SmiMockStrategy : public SmiStrategy
00056     {
00057     public:
00058         SmiMockStrategy(std::string initFilename) : fh(fopen (initFilename.c_str (), "w+b")), filename(initFilename)
00059         {}
00060         ;
00061         virtual ~SmiMockStrategy()
00062         {
00063             fclose (fh);
00064         };
00065 
00066         virtual void lock()
00067         {}
00068         ;
00069         virtual void setSize(int)
00070         {}
00071         ;
00072         virtual size_t getPhysicalBufferBaseAddress()
00073         {
00074             return 0xDEADBEEF;
00075         };
00076         virtual void addInputBuffer(u8 *buffer, size_t size)
00077         {
00078             fwrite(buffer, 1, size, fh);
00079         };
00080         virtual void execute()
00081         {
00082             fseek(fh,0,0);
00083         };
00084         virtual void getResultBuffer(u8 *buffer, size_t size)
00085         {
00086             fread(buffer,1,size,fh);
00087         };
00088         virtual void finish()
00089         {}
00090         ;
00091     private:
00092         FILE *fh;
00093         std::string filename;
00094     };
00095 
00096     class SmiArchStrategy : public SmiStrategy
00097     {
00098     public:
00099         SmiArchStrategy();
00100         virtual ~SmiArchStrategy();
00101 
00102         virtual void lock()
00103             ;
00104         virtual void setSize(int);
00105         virtual size_t getPhysicalBufferBaseAddress();
00106         virtual void addInputBuffer(u8 *buffer, size_t size);
00107         virtual void execute();
00108         virtual void getResultBuffer(u8 *buffer, size_t size);
00109         virtual void finish();
00110 
00111     private:
00112         void *privateData;
00113     };
00114 
00115 
00116     class DellCallingInterfaceSmiImpl : virtual public IDellCallingInterfaceSmi
00117     {
00118     public:
00119         DellCallingInterfaceSmiImpl(SmiStrategy *);
00120         virtual ~DellCallingInterfaceSmiImpl();
00121 
00122         virtual void execute();
00123         virtual void setClass( u16 newClass );
00124         virtual void setSelect( u16 newSelect );
00125         virtual void setArg( u8 argNumber, u32 argValue );
00126         virtual u32  getRes( u8 resNumber ) const;
00127         virtual void setArgAsPhysicalAddress( u8 argNumber, u32 bufferOffset );
00128         virtual u8 *getBufferPtr();
00129         virtual void setBufferSize(size_t newSize);
00130         virtual void setCommandIOMagic( u16 address, u8 code );
00131 
00132     protected:
00133         struct calling_interface_command_buffer smi_buf;
00134         bool argIsAddress[4];
00135         u32  argAddressOffset[4];
00136         struct callintf_cmd                     kernel_buf;
00137         u8                                      *buffer;
00138         size_t                                  bufferSize;
00139         std::auto_ptr<SmiStrategy>              smiStrategy;
00140 
00141 
00142     private:
00143         DellCallingInterfaceSmiImpl();
00144     };
00145 
00146 }
00147 
00148 #endif  /* SMIIMPL_H */

Generated on Tue Jul 11 20:46:46 2006 for SMBIOS Library by  doxygen 1.4.7