22//* This file is part of the *
33//* Mpxplay - audio player. *
44//* The source code of Mpxplay is *
5- //* (C) copyright 1998-2008 by PDSoft (Attila Padar) *
5+ //* (C) copyright 1998-2023 by PDSoft (Attila Padar) *
66//* http://mpxplay.sourceforge.net *
77//* email: mpxplay@freemail.hu *
88//**************************************************************************
1717
1818#include <string.h>
1919#include <dos.h>
20+ #ifdef __WATCOMC__
21+ #include <conio.h>
22+ #endif
23+
2024#include "pcibios.h"
2125
22- struct pci_config_s libau_pci ;
26+ struct pci_config_s libau_pci = { 0 ,0 ,0 ,0 ,0 ,NULL ,0 };
27+
28+ #define PCIBIOS_DIRECTPORT_RW 1
29+
30+ #if PCIBIOS_DIRECTPORT_RW
31+ #ifdef __WATCOMC__
32+ #define pcibios_outportl (reg ,val ) outpd(reg,val)
33+ #define pcibios_inportl (reg ) inpd(reg)
34+ #endif
35+ #ifdef __DJGPP__
36+ #define pcibios_outportl (reg ,val ) outportl(reg,val)
37+ #define pcibios_inportl (reg ) inportl(reg)
38+ #endif
39+ #define PCI_IOPORT_ADDR 0x0CF8
40+ #define PCI_IOPORT_DATA 0x0CFC
41+ #define PCI_ENABLE_BIT 0x80000000
42+ #define PCI_PORTADDR_VALUE (p , a ) (PCI_ENABLE_BIT | ((uint32_t)(p)->bBus << 16) | ((uint32_t)(p)->bDev << 11) | ((uint32_t)(p)->bFunc << 8) | ((uint32_t)(a) & 0xFC))
43+ #endif
2344
2445#define PCIDEVNUM (bParam ) (bParam >> 3)
2546#define PCIFUNCNUM (bParam ) (bParam & 0x07)
@@ -87,8 +108,15 @@ uint8_t pcibios_search_devices(pci_device_s devices[],pci_config_s *ppkey)
87108 return PCI_DEVICE_NOTFOUND ;
88109}
89110
90- uint8_t pcibios_ReadConfig_Byte (pci_config_s * ppkey , uint16_t wAdr )
111+ uint8_t pcibios_ReadConfig_Byte (pci_config_s * ppkey , uint16_t wAdr )
91112{
113+ #if PCIBIOS_DIRECTPORT_RW
114+ const int shift = ((wAdr & 3 ) * 8 );
115+ const uint32_t val = PCI_PORTADDR_VALUE (ppkey , wAdr );
116+ pcibios_outportl (PCI_IOPORT_ADDR , val );
117+ return (pcibios_inportl (PCI_IOPORT_DATA ) >> shift ) & 0xFF ;
118+
119+ #else
92120 union REGS reg ;
93121
94122 memset (& reg ,0 ,sizeof (reg ));
@@ -101,10 +129,22 @@ uint8_t pcibios_ReadConfig_Byte(pci_config_s * ppkey, uint16_t wAdr)
101129 int386 (PCI_SERVICE , & reg , & reg );
102130
103131 return reg .h .cl ;
132+ #endif
104133}
105134
106- uint16_t pcibios_ReadConfig_Word (pci_config_s * ppkey , uint16_t wAdr )
135+ uint16_t pcibios_ReadConfig_Word (pci_config_s * ppkey , uint16_t wAdr )
107136{
137+ #if PCIBIOS_DIRECTPORT_RW
138+ if ((wAdr & 3 ) <= 2 ) {
139+ const int shift = ((wAdr & 3 ) * 8 );
140+ const uint32_t val = PCI_PORTADDR_VALUE (ppkey , wAdr );
141+ pcibios_outportl (PCI_IOPORT_ADDR , val );
142+ return (pcibios_inportl (PCI_IOPORT_DATA ) >> shift ) & 0xFFFF ;
143+ }
144+
145+ return (uint16_t )pcibios_ReadConfig_Byte (ppkey , wAdr ) | ((uint16_t )pcibios_ReadConfig_Byte (ppkey , wAdr + 1 ) << 8 );
146+
147+ #else
108148 union REGS reg ;
109149
110150 memset (& reg ,0 ,sizeof (reg ));
@@ -117,20 +157,39 @@ uint16_t pcibios_ReadConfig_Word(pci_config_s * ppkey, uint16_t wAdr)
117157 int386 (PCI_SERVICE , & reg , & reg );
118158
119159 return reg .w .cx ;
160+ #endif
120161}
121162
122- uint32_t pcibios_ReadConfig_Dword (pci_config_s * ppkey , uint16_t wAdr )
163+ uint32_t pcibios_ReadConfig_Dword (pci_config_s * ppkey , uint16_t wAdr )
123164{
165+ #if PCIBIOS_DIRECTPORT_RW
166+ if ((wAdr & 3 ) == 0 ) {
167+ const uint32_t val = PCI_PORTADDR_VALUE (ppkey , wAdr );
168+ pcibios_outportl (PCI_IOPORT_ADDR , val );
169+ return pcibios_inportl (PCI_IOPORT_DATA );
170+ }
171+
172+ return ((uint32_t )pcibios_ReadConfig_Word (ppkey , (uint8_t )(wAdr + 2 )) << 16L ) | pcibios_ReadConfig_Word (ppkey , wAdr );
173+
174+ #else
124175 uint32_t dwData ;
125176
126177 dwData = (uint32_t )pcibios_ReadConfig_Word (ppkey , wAdr + 2 ) << 16 ;
127178 dwData |= (uint32_t )pcibios_ReadConfig_Word (ppkey , wAdr );
128179
129180 return dwData ;
181+ #endif
130182}
131183
132- void pcibios_WriteConfig_Byte (pci_config_s * ppkey , uint16_t wAdr , uint8_t bData )
184+ void pcibios_WriteConfig_Byte (pci_config_s * ppkey , uint16_t wAdr , uint8_t bData )
133185{
186+ #if PCIBIOS_DIRECTPORT_RW
187+ const int shift = ((wAdr & 3 ) * 8 );
188+ const uint32_t val = PCI_PORTADDR_VALUE (ppkey , wAdr );
189+ pcibios_outportl (PCI_IOPORT_ADDR , val );
190+ pcibios_outportl (PCI_IOPORT_DATA , (uint32_t )(pcibios_inportl (PCI_IOPORT_DATA ) & ~(0xFFU << shift )) | ((uint32_t )bData << shift ));
191+
192+ #else
134193 union REGS reg ;
135194
136195 memset (& reg ,0 ,sizeof (reg ));
@@ -142,10 +201,23 @@ void pcibios_WriteConfig_Byte(pci_config_s * ppkey, uint16_t wAdr, uint8_t bData
142201 reg .w .di = wAdr ;
143202
144203 int386 (PCI_SERVICE , & reg , & reg );
204+ #endif
145205}
146206
147- void pcibios_WriteConfig_Word (pci_config_s * ppkey , uint16_t wAdr , uint16_t wData )
207+ void pcibios_WriteConfig_Word (pci_config_s * ppkey , uint16_t wAdr , uint16_t wData )
148208{
209+ #if PCIBIOS_DIRECTPORT_RW
210+ if ((wAdr & 3 ) <= 2 ) {
211+ const int shift = ((wAdr & 3 ) * 8 );
212+ const uint32_t val = PCI_PORTADDR_VALUE (ppkey , wAdr );
213+ pcibios_outportl (PCI_IOPORT_ADDR , val );
214+ pcibios_outportl (PCI_IOPORT_DATA , (pcibios_inportl (PCI_IOPORT_DATA ) & ~(0xFFFFU << shift )) | ((uint32_t )wData << shift ));
215+ } else {
216+ pcibios_WriteConfig_Byte (ppkey , wAdr , (uint8_t )(wData & 0xFF ));
217+ pcibios_WriteConfig_Byte (ppkey , wAdr + 1 , (uint8_t )(wData >> 8 ));
218+ }
219+
220+ #else
149221 union REGS reg ;
150222
151223 memset (& reg ,0 ,sizeof (reg ));
@@ -157,12 +229,24 @@ void pcibios_WriteConfig_Word(pci_config_s * ppkey, uint16_t wAdr, uint16_t wDat
157229 reg .w .di = wAdr ;
158230
159231 int386 (PCI_SERVICE , & reg , & reg );
232+ #endif
160233}
161234
162- void pcibios_WriteConfig_Dword (pci_config_s * ppkey , uint16_t wAdr , uint32_t dwData )
235+ void pcibios_WriteConfig_Dword (pci_config_s * ppkey , uint16_t wAdr , uint32_t dwData )
163236{
164- pcibios_WriteConfig_Word (ppkey , wAdr , LoW (dwData ));
237+ #if PCIBIOS_DIRECTPORT_RW
238+ if ((wAdr & 3 ) == 0 ) {
239+ const uint32_t val = PCI_PORTADDR_VALUE (ppkey , wAdr );
240+ pcibios_outportl (PCI_IOPORT_ADDR , val );
241+ pcibios_outportl (PCI_IOPORT_DATA , dwData );
242+ } else {
243+ pcibios_WriteConfig_Word (ppkey , wAdr , LoW (dwData ));
244+ pcibios_WriteConfig_Word (ppkey , wAdr + 2 , HiW (dwData ));
245+ }
246+ #else
247+ pcibios_WriteConfig_Word (ppkey , wAdr , LoW (dwData ));
165248 pcibios_WriteConfig_Word (ppkey , wAdr + 2 , HiW (dwData ));
249+ #endif
166250}
167251
168252void pcibios_set_master (pci_config_s * ppkey )
0 commit comments