ia64/xen-unstable

view xen/drivers/pci/pci.c @ 18896:f7f8f44b9292

tools: Fix a few error-path memory leaks.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Dec 09 12:53:19 2008 +0000 (2008-12-09)
parents 69f670979660
children
line source
1 /******************************************************************************
2 * pci.c
3 *
4 * Architecture-independent PCI access functions.
5 */
7 #include <xen/pci.h>
8 #include <xen/pci_regs.h>
10 int pci_find_cap_offset(u8 bus, u8 dev, u8 func, u8 cap)
11 {
12 u8 id;
13 int max_cap = 48;
14 u8 pos = PCI_CAPABILITY_LIST;
15 u16 status;
17 status = pci_conf_read16(bus, dev, func, PCI_STATUS);
18 if ( (status & PCI_STATUS_CAP_LIST) == 0 )
19 return 0;
21 while ( max_cap-- )
22 {
23 pos = pci_conf_read8(bus, dev, func, pos);
24 if ( pos < 0x40 )
25 break;
27 pos &= ~3;
28 id = pci_conf_read8(bus, dev, func, pos + PCI_CAP_LIST_ID);
30 if ( id == 0xff )
31 break;
32 else if ( id == cap )
33 return pos;
35 pos += PCI_CAP_LIST_NEXT;
36 }
38 return 0;
39 }
41 int pci_find_next_cap(u8 bus, unsigned int devfn, u8 pos, int cap)
42 {
43 u8 id;
44 int ttl = 48;
46 while ( ttl-- )
47 {
48 pos = pci_conf_read8(bus, PCI_SLOT(devfn), PCI_FUNC(devfn), pos);
49 if ( pos < 0x40 )
50 break;
52 pos &= ~3;
53 id = pci_conf_read8(bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
54 pos + PCI_CAP_LIST_ID);
56 if ( id == 0xff )
57 break;
58 if ( id == cap )
59 return pos;
61 pos += PCI_CAP_LIST_NEXT;
62 }
63 return 0;
64 }