1 /////////////////////////////////////////////////////////////////////////
2 // $Id: pcidev.h 13150 2017-03-26 08:09:28Z vruppert $
3 /////////////////////////////////////////////////////////////////////////
4 
5 /*
6  *  PCIDEV: PCI host device mapping
7  *  Copyright (C) 2003       Frank Cornelis
8  *  Copyright (C) 2003-2017  The Bochs Project
9  *
10  *  This library is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU Lesser General Public
12  *  License version 2 as published by the Free Software Foundation.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22  */
23 
24 #ifndef BX_IODEV_PCIDEV_H
25 #define BX_IODEV_PCIDEV_H
26 
27 #if BX_USE_PCIDEV_SMF
28 #  define BX_PCIDEV_THIS thePciDevAdapter->
29 #  define BX_PCIDEV_THIS_ thePciDevAdapter
30 #else
31 #  define BX_PCIDEV_THIS this->
32 #  define BX_PCIDEV_THIS_ this
33 #endif
34 
35 struct region_struct {
36   Bit32u config_value;
37   Bit32u start; // can change
38   Bit32u size;
39   Bit32u host_start; // never changes!!!
40   class bx_pcidev_c *pcidev;
41 };
42 
43 class bx_pcidev_c : public bx_pci_device_c {
44 public:
45   bx_pcidev_c();
46   virtual ~bx_pcidev_c();
47   virtual void init(void);
48   virtual void reset(unsigned type);
49 
50   virtual Bit32u pci_read_handler(Bit8u address, unsigned io_len);
51   virtual void   pci_write_handler(Bit8u address, Bit32u value, unsigned io_len);
52 
53   int pcidev_fd; // to access the pcidev
54 
55   // resource mapping
56   struct region_struct regions[6];
57   Bit8u devfunc;
58   Bit8u intpin;
59   Bit8u irq;
60 
61 private:
62   static Bit32u read_handler(void *param, Bit32u address, unsigned io_len);
63   static void write_handler(void *param, Bit32u address, Bit32u value, unsigned io_len);
64 #if !BX_USE_PCIDEV_SMF
65   Bit32u read(void *param, Bit32u address, unsigned io_len);
66   void write(void *param, Bit32u address, Bit32u value, unsigned io_len);
67 #endif
68 };
69 
70 #endif
71