1 /////////////////////////////////////////////////////////////////////////
2 // $Id: pci_ide.h 14112 2021-01-31 10:50:53Z vruppert $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 //  Copyright (C) 2004-2021  The Bochs Project
6 //
7 //  This library is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU Lesser General Public
9 //  License as published by the Free Software Foundation; either
10 //  version 2 of the License, or (at your option) any later version.
11 //
12 //  This library is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //  Lesser General Public License for more details.
16 //
17 //  You should have received a copy of the GNU Lesser General Public
18 //  License along with this library; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20 
21 #ifndef BX_IODEV_PCIIDE_H
22 #define BX_IODEV_PCIIDE_H
23 
24 #if BX_USE_PIDE_SMF
25 #  define BX_PIDE_SMF  static
26 #  define BX_PIDE_THIS thePciIdeController->
27 #  define BX_PIDE_THIS_PTR thePciIdeController
28 #else
29 #  define BX_PIDE_SMF
30 #  define BX_PIDE_THIS this->
31 #  define BX_PIDE_THIS_PTR this
32 #endif
33 
34 class bx_pci_ide_c : public bx_pci_ide_stub_c {
35 public:
36   bx_pci_ide_c();
37   virtual ~bx_pci_ide_c();
38   virtual void init(void);
39   virtual void reset(unsigned type);
40   virtual bool bmdma_present(void);
41   virtual void bmdma_start_transfer(Bit8u channel);
42   virtual void bmdma_set_irq(Bit8u channel);
43   virtual void register_state(void);
44   virtual void after_restore_state(void);
45   static Bit64s param_save_handler(void *devptr, bx_param_c *param);
46   static void param_restore_handler(void *devptr, bx_param_c *param, Bit64s val);
47 #if !BX_USE_PIDE_SMF
48   Bit64s param_save(bx_param_c *param);
49   void param_restore(bx_param_c *param, Bit64s val);
50 #endif
51 
52   virtual void pci_write_handler(Bit8u address, Bit32u value, unsigned io_len);
53 
54   static void timer_handler(void *);
55   BX_PIDE_SMF void timer(void);
56 
57 private:
58 
59   struct {
60     unsigned chipset;
61     struct {
62       bool cmd_ssbm;
63       bool cmd_rwcon;
64       Bit8u  status;
65       Bit32u dtpr;
66       Bit32u prd_current;
67       int timer_index;
68       Bit8u *buffer;
69       Bit8u *buffer_top;
70       Bit8u *buffer_idx;
71       bool data_ready;
72     } bmdma[2];
73   } s;
74 
75   static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
76   static void   write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
77 #if !BX_USE_PIDE_SMF
78   Bit32u read(Bit32u address, unsigned io_len);
79   void   write(Bit32u address, Bit32u value, unsigned io_len);
80 #endif
81 };
82 
83 #endif
84