1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
/***************************************************************************
machine/pci.c
PCI bus
The PCI bus is a 32-bit bus introduced by Intel, so it is little endian
Control word:
bit 31: Enable bit
bits 30-24: Reserved
bits 23-16: PCI bus number
bits 15-11: PCI device number
bits 10- 8: PCI function number
bits 7- 0: Offset address
Standard PCI registers:
0x00 2 Vendor ID
0x02 2 Device ID
0x04 2 PCI Command
0x06 2 PCI Status
0x08 1 Revision ID
0x09 1 Programming Interface
0x0A 1 Subclass Code
0x0B 1 Class Code
Class Code/Subclass Code/Programming Interface
0x00XXXX Pre-PCI 2.0 devices
0x000000 Non-VGA device
0x000101 VGA device
0x01XXXX Storage Controller
0x010000 SCSI
0x0101XX IDE
0x0102XX Floppy
0x0103XX IPI
0x0104XX RAID
0x0180XX Other
0x02XXXX Network Card
0x020000 Ethernet
0x020100 Tokenring
0x020200 FDDI
0x020300 ATM
0x028000 Other
0x03XXXX Display Controller
0x030000 VGA
0x030001 8514 Compatible
0x030100 XGA
0x038000 Other
0x04XXXX Multimedia
0x040000 Video
0x040100 Audio
0x048000 Other
0x05XXXX Memory Controller
0x050000 RAM
0x050100 Flash
0x058000 Other
0x06XXXX Bridge
0x060000 Host/PCI
0x060100 PCI/ISA
0x060200 PCI/EISA
0x060300 PCI/Micro Channel
0x060400 PCI/PCI
0x060500 PCI/PCMCIA
0x060600 PCI/NuBus
0x060700 PCI/CardBus
0x068000 Other
Information on PCI vendors can be found at http://www.pcidatabase.com/
***************************************************************************/
#include "driver.h"
#include "devconv.h"
#include "machine/pci.h"
#define LOG_PCI 0
typedef struct _pci_bus_state pci_bus_state;
struct _pci_bus_state
{
const device_config * busdevice;
const pci_bus_config * config;
const device_config * device[32];
offs_t address;
INT8 devicenum;
};
/***************************************************************************
INLINE FUNCTIONS
***************************************************************************/
/*-------------------------------------------------
get_safe_token - makes sure that the passed
in device is, in fact, an IDE controller
-------------------------------------------------*/
INLINE pci_bus_state *get_safe_token(const device_config *device)
{
assert(device != NULL);
assert(device->token != NULL);
assert(device->type == PCI_BUS);
return (pci_bus_state *)device->token;
}
READ32_DEVICE_HANDLER( pci_32le_r )
{
pci_bus_state *pcibus = get_safe_token(device);
UINT32 result = 0xffffffff;
int function, reg;
offset %= 2;
switch (offset)
{
case 0:
result = pcibus->address;
break;
case 1:
if (pcibus->devicenum != -1)
{
pci_read_func read = pcibus->config->device[pcibus->devicenum].read_callback;
if (read != NULL)
{
function = (pcibus->address >> 8) & 0x07;
reg = (pcibus->address >> 0) & 0xfc;
result = (*read)(device, pcibus->device[pcibus->devicenum], function, reg, mem_mask);
}
}
break;
}
if (LOG_PCI)
logerror("pci_32le_r('%s'): offset=%d result=0x%08X\n", device->tag, offset, result);
return result;
}
WRITE32_DEVICE_HANDLER( pci_32le_w )
{
pci_bus_state *pcibus = get_safe_token(device);
offset %= 2;
if (LOG_PCI)
logerror("pci_32le_w('%s'): offset=%d data=0x%08X\n", device->tag, offset, data);
switch (offset)
{
case 0:
pcibus->address = data;
/* lookup current device */
if (pcibus->address & 0x80000000)
{
int busnum = (pcibus->address >> 16) & 0xff;
int devicenum = (pcibus->address >> 11) & 0x1f;
pcibus->devicenum = (busnum == pcibus->config->busnum) ? devicenum : -1;
}
break;
case 1:
if (pcibus->devicenum != -1)
{
pci_write_func write = pcibus->config->device[pcibus->devicenum].write_callback;
if (write != NULL)
{
int function = (pcibus->address >> 8) & 0x07;
int reg = (pcibus->address >> 0) & 0xfc;
(*write)(device, pcibus->device[pcibus->devicenum], function, reg, data, mem_mask);
}
}
break;
}
}
READ64_DEVICE_HANDLER(pci_64be_r) { return read64be_with_32le_device_handler(pci_32le_r, device, offset, mem_mask); }
WRITE64_DEVICE_HANDLER(pci_64be_w) { write64be_with_32le_device_handler(pci_32le_w, device, offset, data, mem_mask); }
/***************************************************************************
DEVICE INTERFACE
***************************************************************************/
/*-------------------------------------------------
device start callback
-------------------------------------------------*/
static DEVICE_START( pci_bus )
{
pci_bus_state *pcibus = get_safe_token(device);
int devicenum;
/* validate some basic stuff */
assert(device != NULL);
assert(device->static_config == NULL);
assert(device->inline_config != NULL);
assert(device->machine != NULL);
assert(device->machine->config != NULL);
/* store a pointer back to the device */
pcibus->config = (const pci_bus_config *)device->inline_config;
pcibus->busdevice = device;
pcibus->devicenum = -1;
/* find all our devices */
for (devicenum = 0; devicenum < ARRAY_LENGTH(pcibus->device); devicenum++)
if (pcibus->config->device[devicenum].devtag != NULL)
pcibus->device[devicenum] = devtag_get_device(device->machine, pcibus->config->device[devicenum].devtag);
/* register pci states */
state_save_register_device_item(device, 0, pcibus->address);
state_save_register_device_item(device, 0, pcibus->devicenum);
}
/*-------------------------------------------------
device reset callback
-------------------------------------------------*/
static DEVICE_RESET( pci_bus )
{
pci_bus_state *pcibus = get_safe_token(device);
/* reset the drive state */
pcibus->devicenum = -1;
pcibus->address = 0;
}
/*-------------------------------------------------
device set info callback
-------------------------------------------------*/
static DEVICE_SET_INFO( pci_bus )
{
switch (state)
{
/* no parameters to set */
}
}
/*-------------------------------------------------
device get info callback
-------------------------------------------------*/
DEVICE_GET_INFO( pci_bus )
{
switch (state)
{
/* --- the following bits of info are returned as 64-bit signed integers --- */
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(pci_bus_state); break;
case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(pci_bus_config); break;
case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break;
/* --- the following bits of info are returned as pointers to data or functions --- */
case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(pci_bus); break;
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(pci_bus); break;
case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(pci_bus);break;
/* --- the following bits of info are returned as NULL-terminated strings --- */
case DEVINFO_STR_NAME: strcpy(info->s, "PCI Bus"); break;
case DEVINFO_STR_FAMILY: strcpy(info->s, "Peripherial Bus"); break;
case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
}
}
|