Changeset fbfe59d in mainline


Ignore:
Timestamp:
2018-06-25T21:45:05Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8119363
Parents:
2498b95 (diff), e3107e2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'virtio-net'

This commit merges basic support for the virtio-net NIC. As of now, the
driver does not support any advanced features that might be supported by
the device. Also device removal is not yet supported.

Files:
8 added
7 edited

Legend:

Unmodified
Added
Removed
  • boot/Makefile.common

    r2498b95 rfbfe59d  
    139139        nic/rtl8169 \
    140140        nic/ar9271 \
     141        nic/virtio-net \
    141142        block/ahci
    142143
  • tools/ew.py

    r2498b95 rfbfe59d  
    146146        return ' -device rtl8139,vlan=0'
    147147
     148def qemu_nic_virtio_options():
     149        return ' -device virtio-net,vlan=0'
     150
    148151def qemu_net_options():
    149152        if is_override('nonet'):
     
    158161                if 'ne2k' in overrides['net'].keys():
    159162                        nic_options += qemu_nic_ne2k_options()
     163                if 'virtio-net' in overrides['net'].keys():
     164                        nic_options += qemu_nic_virtio_options()
    160165        else:
    161166                # Use the default NIC
     
    326331def usage():
    327332        print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0]))
    328         print("%s [-d] [-h] [-net e1k|rtl8139|ne2k] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb] [-noxhci] [-notablet]\n" %
     333        print("%s [-d] [-h] [-net e1k|rtl8139|ne2k|virtio-net] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb] [-noxhci] [-notablet]\n" %
    329334            os.path.basename(sys.argv[0]))
    330335        print("-d\tDry run: do not run the emulation, just print the command line.")
     
    360365                        elif sys.argv[i] == 'ne2k':
    361366                                overrides['net']['ne2k'] = True
     367                        elif sys.argv[i] == 'virtio-net':
     368                                overrides['net']['virtio-net'] = True
    362369                        else:
    363370                                usage()
  • uspace/Makefile

    r2498b95 rfbfe59d  
    181181        drv/nic/rtl8169 \
    182182        drv/nic/ar9271 \
     183        drv/nic/virtio-net \
    183184        drv/platform/amdm37x \
    184185        drv/platform/icp \
     
    251252        lib/bithenge \
    252253        lib/posix \
    253         lib/ieee80211
     254        lib/ieee80211 \
     255        lib/virtio
    254256
    255257BASE_BUILDS := $(addsuffix .build,$(BASE_LIBS))
  • uspace/drv/bus/pci/pciintel/pci.c

    r2498b95 rfbfe59d  
    738738
    739739                if (pio_enable_resource(&bus->pio_win,
    740                     &hw_resources.resources[0],
    741                     (void **) &bus->conf_space)) {
     740                    &hw_resources.resources[0], (void **) &bus->conf_space,
     741                    NULL, NULL)) {
    742742                        ddf_msg(LVL_ERROR,
    743743                            "Failed to map configuration space.");
     
    759759
    760760                if (pio_enable_resource(&bus->pio_win,
    761                     &hw_resources.resources[0],
    762                     (void **) &bus->conf_addr_reg)) {
     761                    &hw_resources.resources[0], (void **) &bus->conf_addr_reg,
     762                    NULL, NULL)) {
    763763                        ddf_msg(LVL_ERROR,
    764764                            "Failed to enable configuration ports.");
     
    767767                }
    768768                if (pio_enable_resource(&bus->pio_win,
    769                     &hw_resources.resources[1],
    770                     (void **) &bus->conf_data_reg)) {
     769                    &hw_resources.resources[1], (void **) &bus->conf_data_reg,
     770                    NULL, NULL)) {
    771771                        ddf_msg(LVL_ERROR,
    772772                            "Failed to enable configuration ports.");
  • uspace/lib/c/generic/ddi.c

    r2498b95 rfbfe59d  
    220220/** Enable PIO for specified HW resource wrt. to the PIO window.
    221221 *
    222  * @param win      PIO window. May be NULL if the resources are known to be
    223  *                 absolute.
    224  * @param res      Resources specifying the I/O range wrt. to the PIO window.
    225  * @param virt     Virtual address for application's PIO operations.
     222 * @param win        PIO window. May be NULL if the resources are known to be
     223 *                   absolute.
     224 * @param res        Resources specifying the I/O range wrt. to the PIO window.
     225 * @param[out] virt  Virtual address for application's PIO operations.
     226 * @param[out] phys  If non-NULL, physical address of the resource
     227 * @param[out] size  If non-NULL, size of the enabled resource.
    226228 *
    227229 * @return EOK on success.
     
    229231 *
    230232 */
    231 errno_t pio_enable_resource(pio_window_t *win, hw_resource_t *res, void **virt)
     233errno_t pio_enable_resource(pio_window_t *win, hw_resource_t *res, void **virt,
     234    uintptr_t *phys, size_t *size)
    232235{
    233236        uintptr_t addr;
    234         size_t size;
     237        size_t sz;
    235238
    236239        switch (res->type) {
     
    242245                        addr += win->io.base;
    243246                }
    244                 size = res->res.io_range.size;
     247                sz = res->res.io_range.size;
    245248                break;
    246249        case MEM_RANGE:
     
    251254                        addr += win->mem.base;
    252255                }
    253                 size = res->res.mem_range.size;
     256                sz = res->res.mem_range.size;
    254257                break;
    255258        default:
     
    257260        }
    258261
    259         return pio_enable((void *) addr, size, virt);
     262        if (phys)
     263                *phys = addr;
     264        if (size)
     265                *size = sz;
     266
     267        return pio_enable((void *) addr, sz, virt);
    260268}
    261269
  • uspace/lib/c/include/ddi.h

    r2498b95 rfbfe59d  
    4040#include <stdint.h>
    4141#include <sys/time.h>
     42#include <byteorder.h>
    4243#include <abi/ddi/irq.h>
    4344#include <device/hw_res.h>
     
    6465
    6566extern errno_t pio_enable_range(addr_range_t *, void **);
    66 extern errno_t pio_enable_resource(pio_window_t *, hw_resource_t *, void **);
     67extern errno_t pio_enable_resource(pio_window_t *, hw_resource_t *, void **,
     68    uintptr_t *, size_t *);
    6769extern errno_t pio_enable(void *, size_t, void **);
    6870extern errno_t pio_disable(void *, size_t);
     
    8587extern uint64_t pio_read_64(const ioport64_t *);
    8688
     89static inline void pio_write_le16(ioport16_t *reg, uint16_t val)
     90{
     91        pio_write_16(reg, host2uint16_t_le(val));
     92}
     93static inline void pio_write_be16(ioport16_t *reg, uint16_t val)
     94{
     95        pio_write_16(reg, host2uint16_t_be(val));
     96}
     97static inline void pio_write_le32(ioport32_t *reg, uint32_t val)
     98{
     99        pio_write_32(reg, host2uint32_t_le(val));
     100}
     101static inline void pio_write_be32(ioport32_t *reg, uint32_t val)
     102{
     103        pio_write_32(reg, host2uint32_t_be(val));
     104}
     105static inline void pio_write_le64(ioport64_t *reg, uint64_t val)
     106{
     107        pio_write_64(reg, host2uint64_t_le(val));
     108}
     109static inline void pio_write_be64(ioport64_t *reg, uint64_t val)
     110{
     111        pio_write_64(reg, host2uint64_t_be(val));
     112}
     113
     114static inline uint16_t pio_read_le16(const ioport16_t *reg)
     115{
     116        return uint16_t_le2host(pio_read_16(reg));
     117}
     118static inline uint16_t pio_read_be16(const ioport16_t *reg)
     119{
     120        return uint16_t_be2host(pio_read_16(reg));
     121}
     122static inline uint32_t pio_read_le32(const ioport32_t *reg)
     123{
     124        return uint32_t_le2host(pio_read_32(reg));
     125}
     126static inline uint32_t pio_read_be32(const ioport32_t *reg)
     127{
     128        return uint32_t_be2host(pio_read_32(reg));
     129}
     130static inline uint64_t pio_read_le64(const ioport64_t *reg)
     131{
     132        return uint64_t_le2host(pio_read_64(reg));
     133}
     134static inline uint64_t pio_read_be64(const ioport64_t *reg)
     135{
     136        return uint64_t_be2host(pio_read_64(reg));
     137}
     138
    87139static inline uint8_t pio_change_8(ioport8_t *reg, uint8_t val, uint8_t mask,
    88140    useconds_t delay)
  • uspace/lib/drv/include/pci_dev_iface.h

    r2498b95 rfbfe59d  
    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_BAR0        0x10
     48#define PCI_CAP_PTR     0x34
     49
     50#define PCI_BAR_COUNT   6
     51
     52#define PCI_STATUS_CAP_LIST     (1 << 4)
     53
     54#define PCI_CAP_ID(c)   ((c) + 0x0)
     55#define PCI_CAP_NEXT(c) ((c) + 0x1)
     56
     57#define PCI_CAP_PMID            0x1
     58#define PCI_CAP_VENDORSPECID    0x9
    4659
    4760extern errno_t pci_config_space_read_8(async_sess_t *, uint32_t, uint8_t *);
     
    5265extern errno_t pci_config_space_write_16(async_sess_t *, uint32_t, uint16_t);
    5366extern errno_t pci_config_space_write_32(async_sess_t *, uint32_t, uint32_t);
     67
     68static inline errno_t
     69pci_config_space_cap_first(async_sess_t *sess, uint8_t *c, uint8_t *id)
     70{
     71        errno_t rc;
     72        uint16_t status;
     73
     74        rc = pci_config_space_read_16(sess, PCI_STATUS, &status);
     75        if (rc != EOK)
     76                return rc;
     77
     78        if (!(status & PCI_STATUS_CAP_LIST)) {
     79                *c = 0;
     80                return EOK;
     81        }
     82
     83        rc = pci_config_space_read_8(sess, PCI_CAP_PTR, c);
     84        if (rc != EOK)
     85                return rc;
     86        if (!c)
     87                return EOK;
     88        return pci_config_space_read_8(sess, PCI_CAP_ID(*c), id);
     89}
     90
     91static inline errno_t
     92pci_config_space_cap_next(async_sess_t *sess, uint8_t *c, uint8_t *id)
     93{
     94        errno_t rc = pci_config_space_read_8(sess, PCI_CAP_NEXT(*c), c);
     95        if (rc != EOK)
     96                return rc;
     97        if (!c)
     98                return EOK;
     99        return pci_config_space_read_8(sess, PCI_CAP_ID(*c), id);
     100}
    54101
    55102/** PCI device communication interface. */
Note: See TracChangeset for help on using the changeset viewer.