Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset e07257e in mainline


Ignore:
Timestamp:
2018-05-22T19:06:49Z (3 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
69927fa
Parents:
6413967
git-author:
Jakub Jermar <jakub@…> (2018-04-08 20:42:58)
git-committer:
Jakub Jermar <jakub@…> (2018-05-22 19:06:49)
Message:

Add primitives for walking the PCI capability list

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/include/pci_dev_iface.h

    r6413967 re07257e  
    4242#define PCI_VENDOR_ID   0x00
    4343#define PCI_DEVICE_ID   0x02
     44#define PCI_STATUS      0x06
    4445#define PCI_SUB_CLASS   0x0A
    4546#define PCI_BASE_CLASS  0x0B
     47#define PCI_CAP_PTR     0x34
     48
     49#define PCI_STATUS_CAP_LIST     (1 << 4)
     50
     51#define PCI_CAP_ID(c)   ((c) + 0x0)
     52#define PCI_CAP_NEXT(c) ((c) + 0x1)
     53
     54#define PCI_CAP_PMID            0x1
     55#define PCI_CAP_VENDORSPECID    0x9
    4656
    4757extern errno_t pci_config_space_read_8(async_sess_t *, uint32_t, uint8_t *);
     
    5262extern errno_t pci_config_space_write_16(async_sess_t *, uint32_t, uint16_t);
    5363extern errno_t pci_config_space_write_32(async_sess_t *, uint32_t, uint32_t);
     64
     65static inline errno_t
     66pci_config_space_cap_first(async_sess_t *sess, uint8_t *c, uint8_t *id)
     67{
     68        errno_t rc;
     69        uint16_t status;
     70
     71        rc = pci_config_space_read_16(sess, PCI_STATUS, &status);
     72        if (rc != EOK)
     73                return rc;
     74
     75        if (!(status & PCI_STATUS_CAP_LIST)) {
     76                *c = 0;
     77                return EOK;
     78        }
     79
     80        rc = pci_config_space_read_8(sess, PCI_CAP_PTR, c);
     81        if (rc != EOK)
     82                return rc;
     83        if (!c)
     84                return EOK;
     85        return pci_config_space_read_8(sess, PCI_CAP_ID(*c), id);
     86}
     87
     88static inline errno_t
     89pci_config_space_cap_next(async_sess_t *sess, uint8_t *c, uint8_t *id)
     90{
     91        errno_t rc = pci_config_space_read_8(sess, PCI_CAP_NEXT(*c), c);
     92        if (rc != EOK)
     93                return rc;
     94        if (!c)
     95                return EOK;
     96        return pci_config_space_read_8(sess, PCI_CAP_ID(*c), id);
     97}
    5498
    5599/** PCI device communication interface. */
Note: See TracChangeset for help on using the changeset viewer.