Subversion Repositories Kolibri OS

Rev

Rev 1631 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1628 serge 1
 
2
#include 
3
#include 
4
#include 
5
#include 
6
7
 
8
 
9
10
 
11
 * pci_setup_device - fill in class and map information of a device
12
 * @dev: the device structure to fill
13
 *
14
 * Initialize the device structure with information about the device's
15
 * vendor,class,memory and IO-space addresses,IRQ lines etc.
16
 * Called at initialisation of the PCI subsystem and by CardBus services.
17
 * Returns 0 on success and negative if unknown type of device (not normal,
18
 * bridge or CardBus).
19
 */
20
int pci_setup_device(struct pci_dev *dev)
21
{
22
    u32 class;
23
    u8 hdr_type;
24
    struct pci_slot *slot;
25
    int pos = 0;
26
27
 
28
        return -EIO;
29
30
 
31
//    dev->dev.parent = dev->bus->bridge;
32
//    dev->dev.bus = &pci_bus_type;
33
    dev->hdr_type = hdr_type & 0x7f;
34
    dev->multifunction = !!(hdr_type & 0x80);
35
    dev->error_state = pci_channel_io_normal;
36
    set_pcie_port_type(dev);
37
38
 
39
        if (PCI_SLOT(dev->devfn) == slot->number)
40
            dev->slot = slot;
41
42
 
43
       set this higher, assuming the system even supports it.  */
44
    dev->dma_mask = 0xffffffff;
45
46
 
47
//             dev->bus->number, PCI_SLOT(dev->devfn),
48
//             PCI_FUNC(dev->devfn));
49
50
 
51
    dev->revision = class & 0xff;
52
    class >>= 8;                    /* upper 3 bytes */
53
    dev->class = class;
54
    class >>= 8;
55
56
 
57
         dev->vendor, dev->device, class, dev->hdr_type);
58
59
 
60
    dev->cfg_size = pci_cfg_space_size(dev);
61
62
 
63
    dev->current_state = PCI_UNKNOWN;
64
65
 
66
//    pci_fixup_device(pci_fixup_early, dev);
67
    /* device class may be changed after fixup */
68
    class = dev->class >> 8;
69
70
 
71
    case PCI_HEADER_TYPE_NORMAL:            /* standard header */
72
        if (class == PCI_CLASS_BRIDGE_PCI)
73
            goto bad;
74
        pci_read_irq(dev);
75
        pci_read_bases(dev, 6, PCI_ROM_ADDRESS);
76
        pci_read_config_word(dev, PCI_SUBSYSTEM_VENDOR_ID, &dev->subsystem_vendor);
77
        pci_read_config_word(dev, PCI_SUBSYSTEM_ID, &dev->subsystem_device);
78
79
 
80
         *  Do the ugly legacy mode stuff here rather than broken chip
81
         *  quirk code. Legacy mode ATA controllers have fixed
82
         *  addresses. These are not always echoed in BAR0-3, and
83
         *  BAR0-3 in a few cases contain junk!
84
         */
85
        if (class == PCI_CLASS_STORAGE_IDE) {
86
            u8 progif;
87
            pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
88
            if ((progif & 1) == 0) {
89
                dev->resource[0].start = 0x1F0;
90
                dev->resource[0].end = 0x1F7;
91
                dev->resource[0].flags = LEGACY_IO_RESOURCE;
92
                dev->resource[1].start = 0x3F6;
93
                dev->resource[1].end = 0x3F6;
94
                dev->resource[1].flags = LEGACY_IO_RESOURCE;
95
            }
96
            if ((progif & 4) == 0) {
97
                dev->resource[2].start = 0x170;
98
                dev->resource[2].end = 0x177;
99
                dev->resource[2].flags = LEGACY_IO_RESOURCE;
100
                dev->resource[3].start = 0x376;
101
                dev->resource[3].end = 0x376;
102
                dev->resource[3].flags = LEGACY_IO_RESOURCE;
103
            }
104
        }
105
        break;
106
107
 
108
        if (class != PCI_CLASS_BRIDGE_PCI)
109
            goto bad;
110
        /* The PCI-to-PCI bridge spec requires that subtractive
111
           decoding (i.e. transparent) bridge must have programming
112
           interface code of 0x01. */
113
        pci_read_irq(dev);
114
        dev->transparent = ((dev->class & 0xff) == 1);
115
        pci_read_bases(dev, 2, PCI_ROM_ADDRESS1);
116
        set_pcie_hotplug_bridge(dev);
117
        pos = pci_find_capability(dev, PCI_CAP_ID_SSVID);
118
        if (pos) {
119
            pci_read_config_word(dev, pos + PCI_SSVID_VENDOR_ID, &dev->subsystem_vendor);
120
            pci_read_config_word(dev, pos + PCI_SSVID_DEVICE_ID, &dev->subsystem_device);
121
        }
122
        break;
123
124
 
125
        if (class != PCI_CLASS_BRIDGE_CARDBUS)
126
            goto bad;
127
        pci_read_irq(dev);
128
        pci_read_bases(dev, 1, 0);
129
        pci_read_config_word(dev, PCI_CB_SUBSYSTEM_VENDOR_ID, &dev->subsystem_vendor);
130
        pci_read_config_word(dev, PCI_CB_SUBSYSTEM_ID, &dev->subsystem_device);
131
        break;
132
133
 
134
        dbgprintf("unknown header type %02x, "
135
            "ignoring device\n", dev->hdr_type);
136
        return -EIO;
137
138
 
139
        dbgprintf("ignoring class %02x (doesn't match header "
140
            "type %02x)\n", class, dev->hdr_type);
141
        dev->class = PCI_CLASS_NOT_DEFINED;
142
    }
143
144
 
145
    return 0;
146
}
147
148
 
149
 
150
 
151
{
152
    struct pci_dev *dev;
153
154
 
155
    if (!dev)
156
        return NULL;
157
158
 
159
160
 
161
}
162
163
 
164
 * Read the config data for a PCI device, sanity-check it
165
 * and fill in the dev structure...
166
 */
167
static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
168
{
169
    struct pci_dev *dev;
170
    u32 l;
171
    int timeout = 10;
172
173
 
174
        return NULL;
175
176
 
177
    if (l == 0xffffffff || l == 0x00000000 ||
178
        l == 0x0000ffff || l == 0xffff0000)
179
        return NULL;
180
181
 
182
    while (l == 0xffff0001) {
183
        delay(timeout/10);
184
        timeout *= 2;
185
        if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, &l))
186
            return NULL;
187
        /* Card hasn't responded in 60 seconds?  Must be stuck. */
188
        if (delay > 60 * 1000) {
189
            printk(KERN_WARNING "pci %04x:%02x:%02x.%d: not "
190
                    "responding\n", pci_domain_nr(bus),
191
                    bus->number, PCI_SLOT(devfn),
192
                    PCI_FUNC(devfn));
193
            return NULL;
194
        }
195
    }
196
197
 
198
    if (!dev)
199
        return NULL;
200
201
 
202
    dev->devfn = devfn;
203
    dev->vendor = l & 0xffff;
204
    dev->device = (l >> 16) & 0xffff;
205
206
 
207
        kfree(dev);
208
        return NULL;
209
    }
210
211
 
212
}
213
214
 
215
 
216
{
217
    struct pci_dev *dev;
218
219
 
220
    if (dev) {
221
//        pci_dev_put(dev);
222
        return dev;
223
    }
224
225
 
226
    if (!dev)
227
        return NULL;
228
229
 
230
231
 
232
}
233
234
 
235
{
236
    u16 cap;
237
    unsigned pos, next_fn;
238
239
 
240
        return 0;
241
242
 
243
    if (!pos)
244
        return 0;
245
    pci_read_config_word(dev, pos + 4, &cap);
246
    next_fn = cap >> 8;
247
    if (next_fn <= fn)
248
        return 0;
249
    return next_fn;
250
}
251
252
 
253
{
254
    return (fn + 1) % 8;
255
}
256
257
 
258
{
259
    return 0;
260
}
261
262
 
263
{
264
    struct pci_dev *parent = bus->self;
265
    if (!parent || !pci_is_pcie(parent))
266
        return 0;
267
    if (parent->pcie_type == PCI_EXP_TYPE_ROOT_PORT ||
268
        parent->pcie_type == PCI_EXP_TYPE_DOWNSTREAM)
269
        return 1;
270
    return 0;
271
}
272
273
 
274
 * pci_scan_slot - scan a PCI slot on a bus for devices.
275
 * @bus: PCI bus to scan
276
 * @devfn: slot number to scan (must have zero function.)
277
 *
278
 * Scan a PCI slot on the specified PCI bus for devices, adding
279
 * discovered devices to the @bus->devices list.  New devices
280
 * will not have is_added set.
281
 *
282
 * Returns the number of new devices found.
283
 */
284
int pci_scan_slot(struct pci_bus *bus, int devfn)
285
{
286
    unsigned fn, nr = 0;
287
    struct pci_dev *dev;
288
    unsigned (*next_fn)(struct pci_dev *, unsigned) = no_next_fn;
289
290
 
291
        return 0; /* Already scanned the entire slot */
292
293
 
294
    if (!dev)
295
        return 0;
296
    if (!dev->is_added)
297
        nr++;
298
299
 
300
        next_fn = next_ari_fn;
301
    else if (dev->multifunction)
302
        next_fn = next_trad_fn;
303
304
 
305
        dev = pci_scan_single_device(bus, devfn + fn);
306
        if (dev) {
307
            if (!dev->is_added)
308
                nr++;
309
            dev->multifunction = 1;
310
        }
311
    }
312
313
 
314
    if (bus->self && nr)
315
        pcie_aspm_init_link_state(bus->self);
316
317
 
318
}
319
320
 
321
 
322
{
323
    unsigned int devfn, pass, max = bus->secondary;
324
    struct pci_dev *dev;
325
326
 
327
328
 
329
    for (devfn = 0; devfn < 0x100; devfn += 8)
330
        pci_scan_slot(bus, devfn);
331
332
 
333
    max += pci_iov_bus_range(bus);
334
335
 
336
     * After performing arch-dependent fixup of the bus, look behind
337
     * all PCI-to-PCI bridges on this bus.
338
     */
339
    if (!bus->is_added) {
340
        dbgprintf("fixups for bus\n");
341
        pcibios_fixup_bus(bus);
342
        if (pci_is_root_bus(bus))
343
            bus->is_added = 1;
344
    }
345
346
 
347
        list_for_each_entry(dev, &bus->devices, bus_list) {
348
            if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
349
                dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
350
                max = pci_scan_bridge(bus, dev, max, pass);
351
        }
352
353
 
354
     * We've scanned the bus and so we know all about what's on
355
     * the other side of any bridges that may be on this bus plus
356
     * any devices.
357
     *
358
     * Return how far we've got finding sub-buses.
359
     */
360
    dbgprintf("bus scan returning with max=%02x\n", max);
361
    return max;
362
}
363
364
 
365
 * pci_cfg_space_size - get the configuration space size of the PCI device.
366
 * @dev: PCI device
367
 *
368
 * Regular PCI devices have 256 bytes, but PCI-X 2 and PCI Express devices
369
 * have 4096 bytes.  Even if the device is capable, that doesn't mean we can
370
 * access it.  Maybe we don't have a way to generate extended config space
371
 * accesses, or the device is behind a reverse Express bridge.  So we try
372
 * reading the dword at 0x100 which must either be 0 or a valid extended
373
 * capability header.
374
 */
375
int pci_cfg_space_size_ext(struct pci_dev *dev)
376
{
377
    u32 status;
378
    int pos = PCI_CFG_SPACE_SIZE;
379
380
 
381
        goto fail;
382
    if (status == 0xffffffff)
383
        goto fail;
384
385
 
386
387
 
388
    return PCI_CFG_SPACE_SIZE;
389
}
390
391
 
392
{
393
    int pos;
394
    u32 status;
395
    u16 class;
396
397
 
398
    if (class == PCI_CLASS_BRIDGE_HOST)
399
        return pci_cfg_space_size_ext(dev);
400
401
 
402
    if (!pos) {
403
        pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
404
        if (!pos)
405
            goto fail;
406
407
 
408
        if (!(status & (PCI_X_STATUS_266MHZ | PCI_X_STATUS_533MHZ)))
409
            goto fail;
410
    }
411
412
 
413
414
 
415
    return PCI_CFG_SPACE_SIZE;
416
}
417