Subversion Repositories shark

Rev

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

Rev Author Line No. Line
428 giacomo 1
/*
2
 *      $Id: pci.c,v 1.1 2004-01-28 18:32:16 giacomo Exp $
3
 *
4
 *      PCI Bus Services, see include/linux/pci.h for further explanation.
5
 *
6
 *      Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter,
7
 *      David Mosberger-Tang
8
 *
9
 *      Copyright 1997 -- 2000 Martin Mares <mj@ucw.cz>
10
 */
11
 
12
#include <linux/delay.h>
13
#include <linux/init.h>
14
#include <linux/pci.h>
15
#include <linux/module.h>
16
#include <linux/spinlock.h>
17
#include <asm/dma.h>    /* isa_dma_bridge_buggy */
18
 
19
#undef DEBUG
20
 
21
#ifdef DEBUG
22
#define DBG(x...) printk(x)
23
#else
24
#define DBG(x...)
25
#endif
26
 
27
/**
28
 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
29
 * @bus: pointer to PCI bus structure to search
30
 *
31
 * Given a PCI bus, returns the highest PCI bus number present in the set
32
 * including the given PCI bus and its list of child PCI buses.
33
 */
34
unsigned char __devinit
35
pci_bus_max_busnr(struct pci_bus* bus)
36
{
37
        struct list_head *tmp;
38
        unsigned char max, n;
39
 
40
        max = bus->number;
41
        list_for_each(tmp, &bus->children) {
42
                n = pci_bus_max_busnr(pci_bus_b(tmp));
43
                if(n > max)
44
                        max = n;
45
        }
46
        return max;
47
}
48
 
49
/**
50
 * pci_max_busnr - returns maximum PCI bus number
51
 *
52
 * Returns the highest PCI bus number present in the system global list of
53
 * PCI buses.
54
 */
55
unsigned char __devinit
56
pci_max_busnr(void)
57
{
58
        struct pci_bus *bus = NULL;
59
        unsigned char max, n;
60
 
61
        max = 0;
62
        while ((bus = pci_find_next_bus(bus)) != NULL) {
63
                n = pci_bus_max_busnr(bus);
64
                if(n > max)
65
                        max = n;
66
        }
67
        return max;
68
}
69
 
70
/**
71
 * pci_find_capability - query for devices' capabilities
72
 * @dev: PCI device to query
73
 * @cap: capability code
74
 *
75
 * Tell if a device supports a given PCI capability.
76
 * Returns the address of the requested capability structure within the
77
 * device's PCI configuration space or 0 in case the device does not
78
 * support it.  Possible values for @cap:
79
 *
80
 *  %PCI_CAP_ID_PM           Power Management
81
 *
82
 *  %PCI_CAP_ID_AGP          Accelerated Graphics Port
83
 *
84
 *  %PCI_CAP_ID_VPD          Vital Product Data
85
 *
86
 *  %PCI_CAP_ID_SLOTID       Slot Identification
87
 *
88
 *  %PCI_CAP_ID_MSI          Message Signalled Interrupts
89
 *
90
 *  %PCI_CAP_ID_CHSWP        CompactPCI HotSwap
91
 *
92
 *  %PCI_CAP_ID_PCIX         PCI-X
93
 */
94
int
95
pci_find_capability(struct pci_dev *dev, int cap)
96
{
97
        u16 status;
98
        u8 pos, id;
99
        int ttl = 48;
100
 
101
        pci_read_config_word(dev, PCI_STATUS, &status);
102
        if (!(status & PCI_STATUS_CAP_LIST))
103
                return 0;
104
        switch (dev->hdr_type) {
105
        case PCI_HEADER_TYPE_NORMAL:
106
        case PCI_HEADER_TYPE_BRIDGE:
107
                pci_read_config_byte(dev, PCI_CAPABILITY_LIST, &pos);
108
                break;
109
        case PCI_HEADER_TYPE_CARDBUS:
110
                pci_read_config_byte(dev, PCI_CB_CAPABILITY_LIST, &pos);
111
                break;
112
        default:
113
                return 0;
114
        }
115
        while (ttl-- && pos >= 0x40) {
116
                pos &= ~3;
117
                pci_read_config_byte(dev, pos + PCI_CAP_LIST_ID, &id);
118
                if (id == 0xff)
119
                        break;
120
                if (id == cap)
121
                        return pos;
122
                pci_read_config_byte(dev, pos + PCI_CAP_LIST_NEXT, &pos);
123
        }
124
        return 0;
125
}
126
 
127
/**
128
 * pci_bus_find_capability - query for devices' capabilities
129
 * @bus:   the PCI bus to query
130
 * @devfn: PCI device to query
131
 * @cap:   capability code
132
 *
133
 * Like pci_find_capability() but works for pci devices that do not have a
134
 * pci_dev structure set up yet.
135
 *
136
 * Returns the address of the requested capability structure within the
137
 * device's PCI configuration space or 0 in case the device does not
138
 * support it.
139
 */
140
int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap)
141
{
142
        u16 status;
143
        u8 pos, id;
144
        int ttl = 48;
145
        struct pci_dev *dev = bus->self;
146
 
147
        pci_bus_read_config_word(bus, devfn, PCI_STATUS, &status);
148
        if (!(status & PCI_STATUS_CAP_LIST))
149
                return 0;
150
        switch (dev->hdr_type) {
151
        case PCI_HEADER_TYPE_NORMAL:
152
        case PCI_HEADER_TYPE_BRIDGE:
153
                pci_bus_read_config_byte(bus, devfn, PCI_CAPABILITY_LIST, &pos);
154
                break;
155
        case PCI_HEADER_TYPE_CARDBUS:
156
                pci_bus_read_config_byte(bus, devfn, PCI_CB_CAPABILITY_LIST, &pos);
157
                break;
158
        default:
159
                return 0;
160
        }
161
        while (ttl-- && pos >= 0x40) {
162
                pos &= ~3;
163
                pci_bus_read_config_byte(bus, devfn, pos + PCI_CAP_LIST_ID, &id);
164
                if (id == 0xff)
165
                        break;
166
                if (id == cap)
167
                        return pos;
168
                pci_bus_read_config_byte(bus, devfn, pos + PCI_CAP_LIST_NEXT, &pos);
169
        }
170
        return 0;
171
}
172
 
173
/**
174
 * pci_find_parent_resource - return resource region of parent bus of given region
175
 * @dev: PCI device structure contains resources to be searched
176
 * @res: child resource record for which parent is sought
177
 *
178
 *  For given resource region of given device, return the resource
179
 *  region of parent bus the given region is contained in or where
180
 *  it should be allocated from.
181
 */
182
struct resource *
183
pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
184
{
185
        const struct pci_bus *bus = dev->bus;
186
        int i;
187
        struct resource *best = NULL;
188
 
189
        for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
190
                struct resource *r = bus->resource[i];
191
                if (!r)
192
                        continue;
193
                if (res->start && !(res->start >= r->start && res->end <= r->end))
194
                        continue;       /* Not contained */
195
                if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM))
196
                        continue;       /* Wrong type */
197
                if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH))
198
                        return r;       /* Exact match */
199
                if ((res->flags & IORESOURCE_PREFETCH) && !(r->flags & IORESOURCE_PREFETCH))
200
                        best = r;       /* Approximating prefetchable by non-prefetchable */
201
        }
202
        return best;
203
}
204
 
205
/**
206
 * pci_set_power_state - Set the power state of a PCI device
207
 * @dev: PCI device to be suspended
208
 * @state: Power state we're entering
209
 *
210
 * Transition a device to a new power state, using the Power Management
211
 * Capabilities in the device's config space.
212
 *
213
 * RETURN VALUE:
214
 * -EINVAL if trying to enter a lower state than we're already in.
215
 * 0 if we're already in the requested state.
216
 * -EIO if device does not support PCI PM.
217
 * 0 if we can successfully change the power state.
218
 */
219
 
220
int
221
pci_set_power_state(struct pci_dev *dev, int state)
222
{
223
        int pm;
224
        u16 pmcsr;
225
 
226
        /* bound the state we're entering */
227
        if (state > 3) state = 3;
228
 
229
        /* Validate current state:
230
         * Can enter D0 from any state, but if we can only go deeper
231
         * to sleep if we're already in a low power state
232
         */
233
        if (state > 0 && dev->current_state > state)
234
                return -EINVAL;
235
        else if (dev->current_state == state)
236
                return 0;        /* we're already there */
237
 
238
        /* find PCI PM capability in list */
239
        pm = pci_find_capability(dev, PCI_CAP_ID_PM);
240
 
241
        /* abort if the device doesn't support PM capabilities */
242
        if (!pm) return -EIO;
243
 
244
        /* check if this device supports the desired state */
245
        if (state == 1 || state == 2) {
246
                u16 pmc;
247
                pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc);
248
                if (state == 1 && !(pmc & PCI_PM_CAP_D1)) return -EIO;
249
                else if (state == 2 && !(pmc & PCI_PM_CAP_D2)) return -EIO;
250
        }
251
 
252
        /* If we're in D3, force entire word to 0.
253
         * This doesn't affect PME_Status, disables PME_En, and
254
         * sets PowerState to 0.
255
         */
256
        if (dev->current_state >= 3)
257
                pmcsr = 0;
258
        else {
259
                pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
260
                pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
261
                pmcsr |= state;
262
        }
263
 
264
        /* enter specified state */
265
        pci_write_config_word(dev, pm + PCI_PM_CTRL, pmcsr);
266
 
267
        /* Mandatory power management transition delays */
268
        /* see PCI PM 1.1 5.6.1 table 18 */
269
        if(state == 3 || dev->current_state == 3)
270
        {
271
                set_current_state(TASK_UNINTERRUPTIBLE);
272
                schedule_timeout(HZ/100);
273
        }
274
        else if(state == 2 || dev->current_state == 2)
275
                udelay(200);
276
        dev->current_state = state;
277
 
278
        return 0;
279
}
280
 
281
/**
282
 * pci_save_state - save the PCI configuration space of a device before suspending
283
 * @dev: - PCI device that we're dealing with
284
 * @buffer: - buffer to hold config space context
285
 *
286
 * @buffer must be large enough to hold the entire PCI 2.2 config space
287
 * (>= 64 bytes).
288
 */
289
int
290
pci_save_state(struct pci_dev *dev, u32 *buffer)
291
{
292
        int i;
293
        if (buffer) {
294
                /* XXX: 100% dword access ok here? */
295
                for (i = 0; i < 16; i++)
296
                        pci_read_config_dword(dev, i * 4,&buffer[i]);
297
        }
298
        return 0;
299
}
300
 
301
/**
302
 * pci_restore_state - Restore the saved state of a PCI device
303
 * @dev: - PCI device that we're dealing with
304
 * @buffer: - saved PCI config space
305
 *
306
 */
307
int
308
pci_restore_state(struct pci_dev *dev, u32 *buffer)
309
{
310
        int i;
311
 
312
        if (buffer) {
313
                for (i = 0; i < 16; i++)
314
                        pci_write_config_dword(dev,i * 4, buffer[i]);
315
        }
316
        /*
317
         * otherwise, write the context information we know from bootup.
318
         * This works around a problem where warm-booting from Windows
319
         * combined with a D3(hot)->D0 transition causes PCI config
320
         * header data to be forgotten.
321
         */    
322
        else {
323
                for (i = 0; i < 6; i ++)
324
                        pci_write_config_dword(dev,
325
                                               PCI_BASE_ADDRESS_0 + (i * 4),
326
                                               dev->resource[i].start);
327
                pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
328
        }
329
        return 0;
330
}
331
 
332
/**
333
 * pci_enable_device_bars - Initialize some of a device for use
334
 * @dev: PCI device to be initialized
335
 * @bars: bitmask of BAR's that must be configured
336
 *
337
 *  Initialize device before it's used by a driver. Ask low-level code
338
 *  to enable selected I/O and memory resources. Wake up the device if it
339
 *  was suspended. Beware, this function can fail.
340
 */
341
 
342
int
343
pci_enable_device_bars(struct pci_dev *dev, int bars)
344
{
345
        int err;
346
 
347
        pci_set_power_state(dev, 0);
348
        if ((err = pcibios_enable_device(dev, bars)) < 0)
349
                return err;
350
        return 0;
351
}
352
 
353
/**
354
 * pci_enable_device - Initialize device before it's used by a driver.
355
 * @dev: PCI device to be initialized
356
 *
357
 *  Initialize device before it's used by a driver. Ask low-level code
358
 *  to enable I/O and memory. Wake up the device if it was suspended.
359
 *  Beware, this function can fail.
360
 */
361
int
362
pci_enable_device(struct pci_dev *dev)
363
{
364
        return pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
365
}
366
 
367
/**
368
 * pci_disable_device - Disable PCI device after use
369
 * @dev: PCI device to be disabled
370
 *
371
 * Signal to the system that the PCI device is not in use by the system
372
 * anymore.  This only involves disabling PCI bus-mastering, if active.
373
 */
374
void
375
pci_disable_device(struct pci_dev *dev)
376
{
377
        u16 pci_command;
378
 
379
        pci_read_config_word(dev, PCI_COMMAND, &pci_command);
380
        if (pci_command & PCI_COMMAND_MASTER) {
381
                pci_command &= ~PCI_COMMAND_MASTER;
382
                pci_write_config_word(dev, PCI_COMMAND, pci_command);
383
        }
384
}
385
 
386
/**
387
 * pci_enable_wake - enable device to generate PME# when suspended
388
 * @dev: - PCI device to operate on
389
 * @state: - Current state of device.
390
 * @enable: - Flag to enable or disable generation
391
 *
392
 * Set the bits in the device's PM Capabilities to generate PME# when
393
 * the system is suspended.
394
 *
395
 * -EIO is returned if device doesn't have PM Capabilities.
396
 * -EINVAL is returned if device supports it, but can't generate wake events.
397
 * 0 if operation is successful.
398
 *
399
 */
400
int pci_enable_wake(struct pci_dev *dev, u32 state, int enable)
401
{
402
        int pm;
403
        u16 value;
404
 
405
        /* find PCI PM capability in list */
406
        pm = pci_find_capability(dev, PCI_CAP_ID_PM);
407
 
408
        /* If device doesn't support PM Capabilities, but request is to disable
409
         * wake events, it's a nop; otherwise fail */
410
        if (!pm)
411
                return enable ? -EIO : 0;
412
 
413
        /* Check device's ability to generate PME# */
414
        pci_read_config_word(dev,pm+PCI_PM_PMC,&value);
415
 
416
        value &= PCI_PM_CAP_PME_MASK;
417
        value >>= ffs(value);   /* First bit of mask */
418
 
419
        /* Check if it can generate PME# from requested state. */
420
        if (!value || !(value & (1 << state)))
421
                return enable ? -EINVAL : 0;
422
 
423
        pci_read_config_word(dev, pm + PCI_PM_CTRL, &value);
424
 
425
        /* Clear PME_Status by writing 1 to it and enable PME# */
426
        value |= PCI_PM_CTRL_PME_STATUS | PCI_PM_CTRL_PME_ENABLE;
427
 
428
        if (!enable)
429
                value &= ~PCI_PM_CTRL_PME_ENABLE;
430
 
431
        pci_write_config_word(dev, pm + PCI_PM_CTRL, value);
432
 
433
        return 0;
434
}
435
 
436
int
437
pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge)
438
{
439
        u8 pin;
440
 
441
        pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
442
        if (!pin)
443
                return -1;
444
        pin--;
445
        while (dev->bus->self) {
446
                pin = (pin + PCI_SLOT(dev->devfn)) % 4;
447
                dev = dev->bus->self;
448
        }
449
        *bridge = dev;
450
        return pin;
451
}
452
 
453
/**
454
 *      pci_release_region - Release a PCI bar
455
 *      @pdev: PCI device whose resources were previously reserved by pci_request_region
456
 *      @bar: BAR to release
457
 *
458
 *      Releases the PCI I/O and memory resources previously reserved by a
459
 *      successful call to pci_request_region.  Call this function only
460
 *      after all use of the PCI regions has ceased.
461
 */
462
void pci_release_region(struct pci_dev *pdev, int bar)
463
{
464
        if (pci_resource_len(pdev, bar) == 0)
465
                return;
466
        if (pci_resource_flags(pdev, bar) & IORESOURCE_IO)
467
                release_region(pci_resource_start(pdev, bar),
468
                                pci_resource_len(pdev, bar));
469
        else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM)
470
                release_mem_region(pci_resource_start(pdev, bar),
471
                                pci_resource_len(pdev, bar));
472
}
473
 
474
/**
475
 *      pci_request_region - Reserved PCI I/O and memory resource
476
 *      @pdev: PCI device whose resources are to be reserved
477
 *      @bar: BAR to be reserved
478
 *      @res_name: Name to be associated with resource.
479
 *
480
 *      Mark the PCI region associated with PCI device @pdev BR @bar as
481
 *      being reserved by owner @res_name.  Do not access any
482
 *      address inside the PCI regions unless this call returns
483
 *      successfully.
484
 *
485
 *      Returns 0 on success, or %EBUSY on error.  A warning
486
 *      message is also printed on failure.
487
 */
488
int pci_request_region(struct pci_dev *pdev, int bar, char *res_name)
489
{
490
        if (pci_resource_len(pdev, bar) == 0)
491
                return 0;
492
 
493
        if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) {
494
                if (!request_region(pci_resource_start(pdev, bar),
495
                            pci_resource_len(pdev, bar), res_name))
496
                        goto err_out;
497
        }
498
        else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
499
                if (!request_mem_region(pci_resource_start(pdev, bar),
500
                                        pci_resource_len(pdev, bar), res_name))
501
                        goto err_out;
502
        }
503
 
504
        return 0;
505
 
506
err_out:
507
        printk (KERN_WARNING "PCI: Unable to reserve %s region #%d:%lx@%lx for device %s\n",
508
                pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem",
509
                bar + 1, /* PCI BAR # */
510
                pci_resource_len(pdev, bar), pci_resource_start(pdev, bar),
511
                pci_name(pdev));
512
        return -EBUSY;
513
}
514
 
515
 
516
/**
517
 *      pci_release_regions - Release reserved PCI I/O and memory resources
518
 *      @pdev: PCI device whose resources were previously reserved by pci_request_regions
519
 *
520
 *      Releases all PCI I/O and memory resources previously reserved by a
521
 *      successful call to pci_request_regions.  Call this function only
522
 *      after all use of the PCI regions has ceased.
523
 */
524
 
525
void pci_release_regions(struct pci_dev *pdev)
526
{
527
        int i;
528
 
529
        for (i = 0; i < 6; i++)
530
                pci_release_region(pdev, i);
531
}
532
 
533
/**
534
 *      pci_request_regions - Reserved PCI I/O and memory resources
535
 *      @pdev: PCI device whose resources are to be reserved
536
 *      @res_name: Name to be associated with resource.
537
 *
538
 *      Mark all PCI regions associated with PCI device @pdev as
539
 *      being reserved by owner @res_name.  Do not access any
540
 *      address inside the PCI regions unless this call returns
541
 *      successfully.
542
 *
543
 *      Returns 0 on success, or %EBUSY on error.  A warning
544
 *      message is also printed on failure.
545
 */
546
int pci_request_regions(struct pci_dev *pdev, char *res_name)
547
{
548
        int i;
549
 
550
        for (i = 0; i < 6; i++)
551
                if(pci_request_region(pdev, i, res_name))
552
                        goto err_out;
553
        return 0;
554
 
555
err_out:
556
        printk (KERN_WARNING "PCI: Unable to reserve %s region #%d:%lx@%lx for device %s\n",
557
                pci_resource_flags(pdev, i) & IORESOURCE_IO ? "I/O" : "mem",
558
                i + 1, /* PCI BAR # */
559
                pci_resource_len(pdev, i), pci_resource_start(pdev, i),
560
                pci_name(pdev));
561
        while(--i >= 0)
562
                pci_release_region(pdev, i);
563
 
564
        return -EBUSY;
565
}
566
 
567
/**
568
 * pci_set_master - enables bus-mastering for device dev
569
 * @dev: the PCI device to enable
570
 *
571
 * Enables bus-mastering on the device and calls pcibios_set_master()
572
 * to do the needed arch specific settings.
573
 */
574
void
575
pci_set_master(struct pci_dev *dev)
576
{
577
        u16 cmd;
578
 
579
        pci_read_config_word(dev, PCI_COMMAND, &cmd);
580
        if (! (cmd & PCI_COMMAND_MASTER)) {
581
                DBG("PCI: Enabling bus mastering for device %s\n", pci_name(dev));
582
                cmd |= PCI_COMMAND_MASTER;
583
                pci_write_config_word(dev, PCI_COMMAND, cmd);
584
        }
585
        pcibios_set_master(dev);
586
}
587
 
588
#ifndef HAVE_ARCH_PCI_MWI
589
/* This can be overridden by arch code. */
590
u8 pci_cache_line_size = L1_CACHE_BYTES >> 2;
591
 
592
/**
593
 * pci_generic_prep_mwi - helper function for pci_set_mwi
594
 * @dev: the PCI device for which MWI is enabled
595
 *
596
 * Helper function for generic implementation of pcibios_prep_mwi
597
 * function.  Originally copied from drivers/net/acenic.c.
598
 * Copyright 1998-2001 by Jes Sorensen, <jes@trained-monkey.org>.
599
 *
600
 * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
601
 */
602
static int
603
pci_generic_prep_mwi(struct pci_dev *dev)
604
{
605
        u8 cacheline_size;
606
 
607
        if (!pci_cache_line_size)
608
                return -EINVAL;         /* The system doesn't support MWI. */
609
 
610
        /* Validate current setting: the PCI_CACHE_LINE_SIZE must be
611
           equal to or multiple of the right value. */
612
        pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &cacheline_size);
613
        if (cacheline_size >= pci_cache_line_size &&
614
            (cacheline_size % pci_cache_line_size) == 0)
615
                return 0;
616
 
617
        /* Write the correct value. */
618
        pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, pci_cache_line_size);
619
        /* Read it back. */
620
        pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &cacheline_size);
621
        if (cacheline_size == pci_cache_line_size)
622
                return 0;
623
 
624
        printk(KERN_WARNING "PCI: cache line size of %d is not supported "
625
               "by device %s\n", pci_cache_line_size << 2, pci_name(dev));
626
 
627
        return -EINVAL;
628
}
629
#endif /* !HAVE_ARCH_PCI_MWI */
630
 
631
/**
632
 * pci_set_mwi - enables memory-write-invalidate PCI transaction
633
 * @dev: the PCI device for which MWI is enabled
634
 *
635
 * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND,
636
 * and then calls @pcibios_set_mwi to do the needed arch specific
637
 * operations or a generic mwi-prep function.
638
 *
639
 * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
640
 */
641
int
642
pci_set_mwi(struct pci_dev *dev)
643
{
644
        int rc;
645
        u16 cmd;
646
 
647
#ifdef HAVE_ARCH_PCI_MWI
648
        rc = pcibios_prep_mwi(dev);
649
#else
650
        rc = pci_generic_prep_mwi(dev);
651
#endif
652
 
653
        if (rc)
654
                return rc;
655
 
656
        pci_read_config_word(dev, PCI_COMMAND, &cmd);
657
        if (! (cmd & PCI_COMMAND_INVALIDATE)) {
658
                DBG("PCI: Enabling Mem-Wr-Inval for device %s\n", pci_name(dev));
659
                cmd |= PCI_COMMAND_INVALIDATE;
660
                pci_write_config_word(dev, PCI_COMMAND, cmd);
661
        }
662
 
663
        return 0;
664
}
665
 
666
/**
667
 * pci_clear_mwi - disables Memory-Write-Invalidate for device dev
668
 * @dev: the PCI device to disable
669
 *
670
 * Disables PCI Memory-Write-Invalidate transaction on the device
671
 */
672
void
673
pci_clear_mwi(struct pci_dev *dev)
674
{
675
        u16 cmd;
676
 
677
        pci_read_config_word(dev, PCI_COMMAND, &cmd);
678
        if (cmd & PCI_COMMAND_INVALIDATE) {
679
                cmd &= ~PCI_COMMAND_INVALIDATE;
680
                pci_write_config_word(dev, PCI_COMMAND, cmd);
681
        }
682
}
683
 
684
int
685
pci_set_dma_mask(struct pci_dev *dev, u64 mask)
686
{
687
        if (!pci_dma_supported(dev, mask))
688
                return -EIO;
689
 
690
        dev->dma_mask = mask;
691
 
692
        return 0;
693
}
694
 
695
int
696
pci_dac_set_dma_mask(struct pci_dev *dev, u64 mask)
697
{
698
        if (!pci_dac_dma_supported(dev, mask))
699
                return -EIO;
700
 
701
        dev->dma_mask = mask;
702
 
703
        return 0;
704
}
705
 
706
int
707
pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
708
{
709
        if (!pci_dma_supported(dev, mask))
710
                return -EIO;
711
 
712
        dev->consistent_dma_mask = mask;
713
 
714
        return 0;
715
}
716
 
717
static int __devinit pci_init(void)
718
{
719
        struct pci_dev *dev = NULL;
720
 
721
        while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
722
                pci_fixup_device(PCI_FIXUP_FINAL, dev);
723
        }
724
        return 0;
725
}
726
 
727
static int __devinit pci_setup(char *str)
728
{
729
        while (str) {
730
                char *k = strchr(str, ',');
731
                if (k)
732
                        *k++ = 0;
733
                if (*str && (str = pcibios_setup(str)) && *str) {
734
                        /* PCI layer options should be handled here */
735
                        printk(KERN_ERR "PCI: Unknown option `%s'\n", str);
736
                }
737
                str = k;
738
        }
739
        return 1;
740
}
741
 
742
device_initcall(pci_init);
743
 
744
__setup("pci=", pci_setup);
745
 
746
#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
747
/* FIXME: Some boxes have multiple ISA bridges! */
748
struct pci_dev *isa_bridge;
749
EXPORT_SYMBOL(isa_bridge);
750
#endif
751
 
752
EXPORT_SYMBOL(pci_enable_device_bars);
753
EXPORT_SYMBOL(pci_enable_device);
754
EXPORT_SYMBOL(pci_disable_device);
755
EXPORT_SYMBOL(pci_max_busnr);
756
EXPORT_SYMBOL(pci_bus_max_busnr);
757
EXPORT_SYMBOL(pci_find_capability);
758
EXPORT_SYMBOL(pci_bus_find_capability);
759
EXPORT_SYMBOL(pci_release_regions);
760
EXPORT_SYMBOL(pci_request_regions);
761
EXPORT_SYMBOL(pci_release_region);
762
EXPORT_SYMBOL(pci_request_region);
763
EXPORT_SYMBOL(pci_set_master);
764
EXPORT_SYMBOL(pci_set_mwi);
765
EXPORT_SYMBOL(pci_clear_mwi);
766
EXPORT_SYMBOL(pci_set_dma_mask);
767
EXPORT_SYMBOL(pci_dac_set_dma_mask);
768
EXPORT_SYMBOL(pci_set_consistent_dma_mask);
769
EXPORT_SYMBOL(pci_assign_resource);
770
EXPORT_SYMBOL(pci_find_parent_resource);
771
 
772
EXPORT_SYMBOL(pci_set_power_state);
773
EXPORT_SYMBOL(pci_save_state);
774
EXPORT_SYMBOL(pci_restore_state);
775
EXPORT_SYMBOL(pci_enable_wake);
776
 
777
/* Quirk info */
778
 
779
EXPORT_SYMBOL(isa_dma_bridge_buggy);
780
EXPORT_SYMBOL(pci_pci_problems);