DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
include/pci_bus.h
00001 /*
00002  *  Copyright (C) 2002-2015  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef DOSBOX_PCI_H
00020 #define DOSBOX_PCI_H
00021 
00022 #define PCI_MAX_PCIBUSSES                   255
00023 #define PCI_MAX_PCIDEVICES                  32
00024 #define PCI_MAX_PCIFUNCTIONS            8
00025 
00026 class PCI_Device {
00027 public:
00028         /* configuration space */
00029         unsigned char config[256];
00030         unsigned char config_writemask[256];
00031 
00032         PCI_Device(Bit16u vendor, Bit16u device);
00033         virtual ~PCI_Device();
00034 
00035         /* configuration space assistant functions */
00036 
00037         Bit16u getDeviceID() {
00038                 return host_readw(config + 0x02);
00039         }
00040         void setDeviceID(const Bit16u device) {
00041                 return host_writew(config + 0x02,device);
00042         }
00043 
00044         Bit16u getVendorID() {
00045                 return host_readw(config + 0x00);
00046         }
00047         void setVendorID(const Bit16u vendor) {
00048                 return host_writew(config + 0x00,vendor);
00049         }
00050 
00051         /* configuration space I/O */
00052         virtual void config_write(Bit8u regnum,Bitu iolen,Bit32u value) {
00053                 if (iolen == 1) {
00054             const unsigned char mask = config_writemask[regnum];
00055             const unsigned char nmask = ~mask;
00056                         /* only allow writing to the bits marked off as writeable */
00057                         config[regnum] = (config[regnum] & nmask) + ((unsigned char)value & mask);
00058                 }
00059                 else if (iolen == 4 && (regnum&3) == 2) { /* unaligned DWORD write (subdividable into two WORD writes) */
00060                         config_write(regnum,2,value&0xFFFF);
00061                         config_write(regnum+2,2,value>>16);
00062                 }
00063                 else {
00064                         /* subdivide into 8-bit I/O */
00065                         /* NTS: If I recall, this virtual function call means that we'll call the
00066                          *      C++ subclass's config_write() NOT our own--right? */
00067                         for (Bitu i=0;i < iolen;i++) {
00068                                 config_write(regnum+i,1,value&0xFF);
00069                                 value >>= 8U;
00070                         }
00071                 }
00072         }
00073         virtual Bit32u config_read(Bit8u regnum,Bitu iolen) {
00074                 /* subdivide into 8-bit I/O */
00075                 Bit32u v=0;
00076 
00077                 if (iolen == 1)
00078                         return config[regnum];
00079                 else if (iolen == 4 && (regnum&3) == 2) { /* unaligned DWORD read (subdividable into two WORD reads) */
00080                         v = config_read(regnum,2);
00081                         v += config_read(regnum+2,2) << 16;
00082                 }
00083                 else {
00084                         /* NTS: If I recall, this virtual function call means that we'll call the
00085                          *      C++ subclass's config_read() NOT our own--right? */
00086                         for (Bitu i=0;i < iolen;i++)
00087                                 v += ((config_read(regnum+i,1)&0xFF) << ((iolen-i-1)*8));
00088                 }
00089 
00090                 return v;
00091         }
00092 };
00093 
00094 bool PCI_IsInitialized();
00095 
00096 void PCI_AddSVGAS3_Device(void);
00097 void PCI_RemoveSVGAS3_Device(void);
00098 
00099 void PCI_AddSST_Device(Bitu type);
00100 void PCI_RemoveSST_Device(void);
00101 
00102 RealPt PCI_GetPModeInterface(void);
00103 
00104 #endif
00105