Subversion Repositories Kolibri OS

Rev

Rev 1630 | Rev 2004 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1630 Rev 1963
Line 1... Line -...
1
#include 
-
 
2
#include 
1
#include 
3
#include 
-
 
4
#include 
2
#include 
-
 
3
#include 
5
#include 
4
#include 
-
 
5
#include 
6
#include 
6
#include 
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
static LIST_HEAD(devices);
8
static LIST_HEAD(devices);
Line 93... Line 93...
93
 
93
 
Line 94... Line 94...
94
        res  = &dev->resource[pos];
94
        res  = &dev->resource[pos];
Line 95... Line 95...
95
 
95
 
96
        reg = PCI_BASE_ADDRESS_0 + (pos << 2);
96
        reg = PCI_BASE_ADDRESS_0 + (pos << 2);
97
        l = PciRead32(dev->busnr, dev->devfn, reg);
97
        l = PciRead32(dev->bus, dev->devfn, reg);
98
        PciWrite32(dev->busnr, dev->devfn, reg, ~0);
98
        PciWrite32(dev->bus, dev->devfn, reg, ~0);
99
        sz = PciRead32(dev->busnr, dev->devfn, reg);
99
        sz = PciRead32(dev->bus, dev->devfn, reg);
Line 100... Line 100...
100
        PciWrite32(dev->busnr, dev->devfn, reg, l);
100
        PciWrite32(dev->bus, dev->devfn, reg, l);
101
 
101
 
Line 102... Line 102...
102
        if (!sz || sz == 0xffffffff)
102
        if (!sz || sz == 0xffffffff)
Line 132... Line 132...
132
        if (is_64bit_memory(l))
132
        if (is_64bit_memory(l))
133
        {
133
        {
134
            u32_t szhi, lhi;
134
            u32_t szhi, lhi;
135
 
135
 
Line 136... Line 136...
136
            lhi = PciRead32(dev->busnr, dev->devfn, reg+4);
136
            lhi = PciRead32(dev->bus, dev->devfn, reg+4);
137
            PciWrite32(dev->busnr, dev->devfn, reg+4, ~0);
137
            PciWrite32(dev->bus, dev->devfn, reg+4, ~0);
138
            szhi = PciRead32(dev->busnr, dev->devfn, reg+4);
138
            szhi = PciRead32(dev->bus, dev->devfn, reg+4);
139
            PciWrite32(dev->busnr, dev->devfn, reg+4, lhi);
139
            PciWrite32(dev->bus, dev->devfn, reg+4, lhi);
140
            sz64 = ((u64_t)szhi << 32) | raw_sz;
140
            sz64 = ((u64_t)szhi << 32) | raw_sz;
141
            l64 = ((u64_t)lhi << 32) | l;
141
            l64 = ((u64_t)lhi << 32) | l;
142
            sz64 = pci_size64(l64, sz64, PCI_BASE_ADDRESS_MEM_MASK);
142
            sz64 = pci_size64(l64, sz64, PCI_BASE_ADDRESS_MEM_MASK);
143
            next++;
143
            next++;
Line 160... Line 160...
160
            }
160
            }
161
            else if (lhi)
161
            else if (lhi)
162
            {
162
            {
163
                /* 64-bit wide address, treat as disabled */
163
                /* 64-bit wide address, treat as disabled */
164
                PciWrite32(dev->busnr, dev->devfn, reg,
164
                PciWrite32(dev->bus, dev->devfn, reg,
165
                        l & ~(u32_t)PCI_BASE_ADDRESS_MEM_MASK);
165
                        l & ~(u32_t)PCI_BASE_ADDRESS_MEM_MASK);
166
                PciWrite32(dev->busnr, dev->devfn, reg+4, 0);
166
                PciWrite32(dev->bus, dev->devfn, reg+4, 0);
167
                res->start = 0;
167
                res->start = 0;
168
                res->end = sz;
168
                res->end = sz;
169
            }
169
            }
170
#endif
170
#endif
171
        }
171
        }
172
    }
172
    }
Line 175... Line 175...
175
    {
175
    {
176
        dev->rom_base_reg = rom;
176
        dev->rom_base_reg = rom;
177
        res = &dev->resource[PCI_ROM_RESOURCE];
177
        res = &dev->resource[PCI_ROM_RESOURCE];
178
 
178
 
Line 179... Line 179...
179
        l = PciRead32(dev->busnr, dev->devfn, rom);
179
        l = PciRead32(dev->bus, dev->devfn, rom);
180
        PciWrite32(dev->busnr, dev->devfn, rom, ~PCI_ROM_ADDRESS_ENABLE);
180
        PciWrite32(dev->bus, dev->devfn, rom, ~PCI_ROM_ADDRESS_ENABLE);
181
        sz = PciRead32(dev->busnr, dev->devfn, rom);
181
        sz = PciRead32(dev->bus, dev->devfn, rom);
182
        PciWrite32(dev->busnr, dev->devfn, rom, l);
182
        PciWrite32(dev->bus, dev->devfn, rom, l);
Line 183... Line 183...
183
 
183
 
184
        if (l == 0xffffffff)
184
        if (l == 0xffffffff)
Line 185... Line 185...
185
            l = 0;
185
            l = 0;
Line 203... Line 203...
203
static void pci_read_irq(struct pci_dev *dev)
203
static void pci_read_irq(struct pci_dev *dev)
204
{
204
{
205
    u8_t irq;
205
    u8_t irq;
Line 206... Line 206...
206
 
206
 
207
    irq = PciRead8(dev->busnr, dev->devfn, PCI_INTERRUPT_PIN);
207
    irq = PciRead8(dev->bus, dev->devfn, PCI_INTERRUPT_PIN);
208
    dev->pin = irq;
208
    dev->pin = irq;
209
    if (irq)
209
    if (irq)
210
        PciRead8(dev->busnr, dev->devfn, PCI_INTERRUPT_LINE);
210
        PciRead8(dev->bus, dev->devfn, PCI_INTERRUPT_LINE);
211
    dev->irq = irq;
211
    dev->irq = irq;
Line 212... Line 212...
212
};
212
};
213
 
213
 
214
 
214
 
Line 215... Line 215...
215
static int pci_setup_device(struct pci_dev *dev)
215
static int pci_setup_device(struct pci_dev *dev)
216
{
216
{
217
    u32_t  class;
217
    u32_t  class;
218
 
218
 
Line 219... Line 219...
219
    class = PciRead32(dev->busnr, dev->devfn, PCI_CLASS_REVISION);
219
    class = PciRead32(dev->bus, dev->devfn, PCI_CLASS_REVISION);
Line 234... Line 234...
234
            if (class == PCI_CLASS_BRIDGE_PCI)
234
            if (class == PCI_CLASS_BRIDGE_PCI)
235
                goto bad;
235
                goto bad;
236
            pci_read_irq(dev);
236
            pci_read_irq(dev);
237
            pci_read_bases(dev, 6, PCI_ROM_ADDRESS);
237
            pci_read_bases(dev, 6, PCI_ROM_ADDRESS);
238
            dev->subsystem_vendor = PciRead16(dev->busnr, dev->devfn,PCI_SUBSYSTEM_VENDOR_ID);
238
            dev->subsystem_vendor = PciRead16(dev->bus, dev->devfn,PCI_SUBSYSTEM_VENDOR_ID);
239
            dev->subsystem_device = PciRead16(dev->busnr, dev->devfn, PCI_SUBSYSTEM_ID);
239
            dev->subsystem_device = PciRead16(dev->bus, dev->devfn, PCI_SUBSYSTEM_ID);
240
 
240
 
Line 241... Line 241...
241
            /*
241
            /*
242
             *      Do the ugly legacy mode stuff here rather than broken chip
242
             *      Do the ugly legacy mode stuff here rather than broken chip
243
             *      quirk code. Legacy mode ATA controllers have fixed
243
             *      quirk code. Legacy mode ATA controllers have fixed
244
             *      addresses. These are not always echoed in BAR0-3, and
244
             *      addresses. These are not always echoed in BAR0-3, and
Line 247... Line 247...
247
            if (class == PCI_CLASS_STORAGE_IDE)
247
            if (class == PCI_CLASS_STORAGE_IDE)
248
            {
248
            {
249
                u8_t progif;
249
                u8_t progif;
250
 
250
 
Line 251... Line 251...
251
                progif = PciRead8(dev->busnr, dev->devfn,PCI_CLASS_PROG);
251
                progif = PciRead8(dev->bus, dev->devfn,PCI_CLASS_PROG);
252
                if ((progif & 1) == 0)
252
                if ((progif & 1) == 0)
253
                {
253
                {
254
                    dev->resource[0].start = 0x1F0;
254
                    dev->resource[0].start = 0x1F0;
255
                    dev->resource[0].end = 0x1F7;
255
                    dev->resource[0].end = 0x1F7;
256
                    dev->resource[0].flags = LEGACY_IO_RESOURCE;
256
                    dev->resource[0].flags = LEGACY_IO_RESOURCE;
Line 285... Line 285...
285
                if (class != PCI_CLASS_BRIDGE_CARDBUS)
285
                if (class != PCI_CLASS_BRIDGE_CARDBUS)
286
                        goto bad;
286
                        goto bad;
287
                pci_read_irq(dev);
287
                pci_read_irq(dev);
288
                pci_read_bases(dev, 1, 0);
288
                pci_read_bases(dev, 1, 0);
289
                dev->subsystem_vendor = PciRead16(dev->busnr,
289
                dev->subsystem_vendor = PciRead16(dev->bus,
290
                                                  dev->devfn,
290
                                                  dev->devfn,
291
                                                  PCI_CB_SUBSYSTEM_VENDOR_ID);
291
                                                  PCI_CB_SUBSYSTEM_VENDOR_ID);
292
 
292
 
Line 293... Line 293...
293
                dev->subsystem_device = PciRead16(dev->busnr,
293
                dev->subsystem_device = PciRead16(dev->bus,
294
                                                  dev->devfn,
294
                                                  dev->devfn,
295
                                                  PCI_CB_SUBSYSTEM_ID);
295
                                                  PCI_CB_SUBSYSTEM_ID);
296
                break;
296
                break;
Line 297... Line 297...
297
 
297
 
Line 352... Line 352...
352
 
352
 
Line 353... Line 353...
353
    if(unlikely(dev == NULL))
353
    if(unlikely(dev == NULL))
354
        return NULL;
354
        return NULL;
Line 355... Line 355...
355
 
355
 
356
    dev->pci_dev.busnr      = bus;
356
    dev->pci_dev.bus      = bus;
357
    dev->pci_dev.devfn    = devfn;
357
    dev->pci_dev.devfn    = devfn;
358
    dev->pci_dev.hdr_type = hdr & 0x7f;
358
    dev->pci_dev.hdr_type = hdr & 0x7f;
359
    dev->pci_dev.multifunction    = !!(hdr & 0x80);
359
    dev->pci_dev.multifunction    = !!(hdr & 0x80);
360
    dev->pci_dev.vendor   = id & 0xffff;
360
    dev->pci_dev.vendor   = id & 0xffff;
Line 503... Line 503...
503
int pci_find_capability(struct pci_dev *dev, int cap)
503
int pci_find_capability(struct pci_dev *dev, int cap)
504
{
504
{
505
    int pos;
505
    int pos;
Line 506... Line 506...
506
 
506
 
507
    pos = __pci_bus_find_cap_start(dev->busnr, dev->devfn, dev->hdr_type);
507
    pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
508
    if (pos)
508
    if (pos)
Line 509... Line 509...
509
        pos = __pci_find_next_cap(dev->busnr, dev->devfn, pos, cap);
509
        pos = __pci_find_next_cap(dev->bus, dev->devfn, pos, cap);
510
 
510
 
Line -... Line 511...
-
 
511
    return pos;
-
 
512
}
-
 
513
 
-
 
514
 
-
 
515
#if 0
-
 
516
/**
-
 
517
 * pci_set_power_state - Set the power state of a PCI device
-
 
518
 * @dev: PCI device to be suspended
-
 
519
 * @state: PCI power state (D0, D1, D2, D3hot, D3cold) we're entering
-
 
520
 *
-
 
521
 * Transition a device to a new power state, using the Power Management
-
 
522
 * Capabilities in the device's config space.
-
 
523
 *
-
 
524
 * RETURN VALUE:
-
 
525
 * -EINVAL if trying to enter a lower state than we're already in.
-
 
526
 * 0 if we're already in the requested state.
-
 
527
 * -EIO if device does not support PCI PM.
-
 
528
 * 0 if we can successfully change the power state.
-
 
529
 */
-
 
530
int
-
 
531
pci_set_power_state(struct pci_dev *dev, pci_power_t state)
-
 
532
{
-
 
533
        int pm, need_restore = 0;
-
 
534
        u16 pmcsr, pmc;
-
 
535
 
-
 
536
        /* bound the state we're entering */
-
 
537
        if (state > PCI_D3hot)
-
 
538
                state = PCI_D3hot;
-
 
539
 
-
 
540
        /*
-
 
541
         * If the device or the parent bridge can't support PCI PM, ignore
-
 
542
         * the request if we're doing anything besides putting it into D0
-
 
543
         * (which would only happen on boot).
-
 
544
         */
-
 
545
        if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
-
 
546
                return 0;
-
 
547
 
-
 
548
        /* find PCI PM capability in list */
-
 
549
        pm = pci_find_capability(dev, PCI_CAP_ID_PM);
-
 
550
 
-
 
551
        /* abort if the device doesn't support PM capabilities */
-
 
552
        if (!pm)
-
 
553
                return -EIO;
-
 
554
 
-
 
555
        /* Validate current state:
-
 
556
         * Can enter D0 from any state, but if we can only go deeper
-
 
557
         * to sleep if we're already in a low power state
-
 
558
         */
-
 
559
        if (state != PCI_D0 && dev->current_state > state) {
-
 
560
                printk(KERN_ERR "%s(): %s: state=%d, current state=%d\n",
-
 
561
                        __FUNCTION__, pci_name(dev), state, dev->current_state);
-
 
562
                return -EINVAL;
-
 
563
        } else if (dev->current_state == state)
-
 
564
                return 0;        /* we're already there */
-
 
565
 
-
 
566
 
-
 
567
        pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc);
-
 
568
        if ((pmc & PCI_PM_CAP_VER_MASK) > 3) {
-
 
569
                printk(KERN_DEBUG
-
 
570
                       "PCI: %s has unsupported PM cap regs version (%u)\n",
-
 
571
                       pci_name(dev), pmc & PCI_PM_CAP_VER_MASK);
-
 
572
                return -EIO;
-
 
573
        }
-
 
574
 
-
 
575
        /* check if this device supports the desired state */
-
 
576
        if (state == PCI_D1 && !(pmc & PCI_PM_CAP_D1))
-
 
577
                return -EIO;
-
 
578
        else if (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2))
-
 
579
                return -EIO;
-
 
580
 
-
 
581
        pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
-
 
582
 
-
 
583
        /* If we're (effectively) in D3, force entire word to 0.
-
 
584
         * This doesn't affect PME_Status, disables PME_En, and
-
 
585
         * sets PowerState to 0.
-
 
586
         */
-
 
587
        switch (dev->current_state) {
-
 
588
        case PCI_D0:
-
 
589
        case PCI_D1:
-
 
590
        case PCI_D2:
-
 
591
                pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
-
 
592
                pmcsr |= state;
-
 
593
                break;
-
 
594
        case PCI_UNKNOWN: /* Boot-up */
-
 
595
                if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
-
 
596
                 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
-
 
597
                        need_restore = 1;
-
 
598
                /* Fall-through: force to D0 */
-
 
599
        default:
-
 
600
                pmcsr = 0;
-
 
601
                break;
-
 
602
        }
-
 
603
 
-
 
604
        /* enter specified state */
-
 
605
        pci_write_config_word(dev, pm + PCI_PM_CTRL, pmcsr);
-
 
606
 
-
 
607
        /* Mandatory power management transition delays */
-
 
608
        /* see PCI PM 1.1 5.6.1 table 18 */
-
 
609
        if (state == PCI_D3hot || dev->current_state == PCI_D3hot)
-
 
610
                msleep(pci_pm_d3_delay);
-
 
611
        else if (state == PCI_D2 || dev->current_state == PCI_D2)
-
 
612
                udelay(200);
-
 
613
 
-
 
614
        /*
-
 
615
         * Give firmware a chance to be called, such as ACPI _PRx, _PSx
-
 
616
         * Firmware method after native method ?
-
 
617
         */
-
 
618
        if (platform_pci_set_power_state)
-
 
619
                platform_pci_set_power_state(dev, state);
-
 
620
 
-
 
621
        dev->current_state = state;
-
 
622
 
-
 
623
        /* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
-
 
624
         * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning
-
 
625
         * from D3hot to D0 _may_ perform an internal reset, thereby
-
 
626
         * going to "D0 Uninitialized" rather than "D0 Initialized".
-
 
627
         * For example, at least some versions of the 3c905B and the
-
 
628
         * 3c556B exhibit this behaviour.
-
 
629
         *
-
 
630
         * At least some laptop BIOSen (e.g. the Thinkpad T21) leave
-
 
631
         * devices in a D3hot state at boot.  Consequently, we need to
-
 
632
         * restore at least the BARs so that the device will be
-
 
633
         * accessible to its driver.
-
 
634
         */
-
 
635
        if (need_restore)
-
 
636
                pci_restore_bars(dev);
Line 511... Line 637...
511
    return pos;
637
 
512
}
638
        return 0;
513
 
639
}
514
 
640
#endif
515
 
641
 
Line 516... Line 642...
516
int pcibios_enable_resources(struct pci_dev *dev, int mask)
642
int pcibios_enable_resources(struct pci_dev *dev, int mask)
517
{
643
{
518
    u16_t cmd, old_cmd;
644
    u16_t cmd, old_cmd;
519
    int  idx;
645
    int  idx;
520
    struct resource *r;
646
    struct resource *r;
521
 
647
 
Line 546... Line 672...
546
    }
672
    }
547
    if (cmd != old_cmd) {
673
    if (cmd != old_cmd) {
548
        printk("PCI: Enabling device %s (%04x -> %04x)\n",
674
        printk("PCI: Enabling device %s (%04x -> %04x)\n",
549
                pci_name(dev), old_cmd, cmd);
675
                pci_name(dev), old_cmd, cmd);
550
        PciWrite16(dev->busnr, dev->devfn, PCI_COMMAND, cmd);
676
        PciWrite16(dev->bus, dev->devfn, PCI_COMMAND, cmd);
551
    }
677
    }
552
    return 0;
678
    return 0;
553
}
679
}
554
 
680
 
Line 640... Line 766...
640
                return  ent;
766
                return  ent;
641
            }
767
            }
642
        };
768
        };
643
    }
769
    }
644
    return NULL;
770
 
-
 
771
    return NULL;
645
};
772
};
646
 
773
 
Line 666... Line 793...
666
    u32_t start;
793
    u32_t start;
667
    void  *rom;
794
    void  *rom;
668
 
795
 
Line 669... Line 796...
669
#if 0
796
#if 0
-
 
797
    /*
-
 
798
     * IORESOURCE_ROM_SHADOW set on x86, x86_64 and IA64 supports legacy
-
 
799
     * memory map if the VGA enable bit of the Bridge Control register is
-
 
800
     * set for embedded VGA.
-
 
801
     */
-
 
802
    if (res->flags & IORESOURCE_ROM_SHADOW) {
-
 
803
        /* primary video rom always starts here */
-
 
804
        start = (u32_t)0xC0000;
-
 
805
        *size = 0x20000; /* cover C000:0 through E000:0 */
-
 
806
    } else {
-
 
807
        if (res->flags & (IORESOURCE_ROM_COPY | IORESOURCE_ROM_BIOS_COPY)) {
-
 
808
            *size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
-
 
809
             return (void *)(unsigned long)
-
 
810
                     pci_resource_start(pdev, PCI_ROM_RESOURCE);
-
 
811
        } else {
-
 
812
                /* assign the ROM an address if it doesn't have one */
-
 
813
            //if (res->parent == NULL &&
-
 
814
            //     pci_assign_resource(pdev,PCI_ROM_RESOURCE))
-
 
815
            //         return NULL;
-
 
816
             start = pci_resource_start(pdev, PCI_ROM_RESOURCE);
-
 
817
             *size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
-
 
818
             if (*size == 0)
-
 
819
                     return NULL;
-
 
820
 
-
 
821
             /* Enable ROM space decodes */
-
 
822
             if (pci_enable_rom(pdev))
-
 
823
                     return NULL;
-
 
824
        }
-
 
825
    }
-
 
826
 
-
 
827
    rom = ioremap(start, *size);
-
 
828
    if (!rom) {
-
 
829
            /* restore enable if ioremap fails */
-
 
830
            if (!(res->flags & (IORESOURCE_ROM_ENABLE |
-
 
831
                                IORESOURCE_ROM_SHADOW |
-
 
832
                                IORESOURCE_ROM_COPY)))
-
 
833
                    pci_disable_rom(pdev);
-
 
834
            return NULL;
-
 
835
    }
-
 
836
 
-
 
837
    /*
-
 
838
     * Try to find the true size of the ROM since sometimes the PCI window
-
 
839
     * size is much larger than the actual size of the ROM.
-
 
840
     * True size is important if the ROM is going to be copied.
-
 
841
     */
-
 
842
    *size = pci_get_rom_size(rom, *size);
-
 
843
 
670
#endif
844
#endif
Line 671... Line 845...
671
 
845
 
672
    unsigned char tmp[32];
846
    unsigned char tmp[32];
Line 697... Line 871...
697
 
871
 
Line 698... Line 872...
698
        return 0;
872
        return 0;
699
}
873
}
Line -... Line 874...
-
 
874