Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

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