Changeset 76b5a95c in mainline for uspace/srv


Ignore:
Timestamp:
2011-03-23T20:53:30Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
71af5a4
Parents:
5716e9a (diff), ab10b842 (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 mainline changes.

Location:
uspace/srv
Files:
1 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/ata_bd/ata_bd.c

    r5716e9a r76b5a95c  
    5555#include <as.h>
    5656#include <fibril_synch.h>
     57#include <stdint.h>
    5758#include <str.h>
    5859#include <devmap.h>
     
    6162#include <errno.h>
    6263#include <bool.h>
     64#include <byteorder.h>
    6365#include <task.h>
    6466#include <macros.h>
     
    7375#define LEGACY_CTLS 4
    7476
    75 /** Physical block size. Should be always 512. */
    76 static const size_t block_size = 512;
     77/**
     78 * Size of data returned from Identify Device or Identify Packet Device
     79 * command.
     80 */
     81static const size_t identify_data_size = 512;
    7782
    7883/** Size of the communication area. */
     
    105110static int ata_bd_write_blocks(int disk_id, uint64_t ba, size_t cnt,
    106111    const void *buf);
    107 static int ata_bd_read_block(int disk_id, uint64_t ba, size_t cnt,
     112static int ata_rcmd_read(int disk_id, uint64_t ba, size_t cnt,
    108113    void *buf);
    109 static int ata_bd_write_block(int disk_id, uint64_t ba, size_t cnt,
     114static int ata_rcmd_write(int disk_id, uint64_t ba, size_t cnt,
    110115    const void *buf);
    111116static int disk_init(disk_t *d, int disk_id);
    112117static int drive_identify(int drive_id, void *buf);
     118static int identify_pkt_dev(int dev_idx, void *buf);
     119static int ata_cmd_packet(int dev_idx, const void *cpkt, size_t cpkt_size,
     120    void *obuf, size_t obuf_size);
     121static int ata_pcmd_inquiry(int dev_idx, void *obuf, size_t obuf_size);
     122static int ata_pcmd_read_12(int dev_idx, uint64_t ba, size_t cnt,
     123    void *obuf, size_t obuf_size);
    113124static void disk_print_summary(disk_t *d);
    114125static int coord_calc(disk_t *d, uint64_t ba, block_coord_t *bc);
     
    203214        printf("%s: ", d->model);
    204215
    205         switch (d->amode) {
    206         case am_chs:
    207                 printf("CHS %u cylinders, %u heads, %u sectors",
    208                     disk->geom.cylinders, disk->geom.heads, disk->geom.sectors);
    209                 break;
    210         case am_lba28:
    211                 printf("LBA-28");
    212                 break;
    213         case am_lba48:
    214                 printf("LBA-48");
    215                 break;
     216        if (d->dev_type == ata_reg_dev) {
     217                switch (d->amode) {
     218                case am_chs:
     219                        printf("CHS %u cylinders, %u heads, %u sectors",
     220                            disk->geom.cylinders, disk->geom.heads,
     221                            disk->geom.sectors);
     222                        break;
     223                case am_lba28:
     224                        printf("LBA-28");
     225                        break;
     226                case am_lba48:
     227                        printf("LBA-48");
     228                        break;
     229                }
     230        } else {
     231                printf("PACKET");
    216232        }
    217233
     
    313329                            IPC_GET_ARG2(call));
    314330                        cnt = IPC_GET_ARG3(call);
    315                         if (cnt * block_size > comm_size) {
     331                        if (cnt * disk[disk_id].block_size > comm_size) {
    316332                                retval = ELIMIT;
    317333                                break;
     
    323339                            IPC_GET_ARG2(call));
    324340                        cnt = IPC_GET_ARG3(call);
    325                         if (cnt * block_size > comm_size) {
     341                        if (cnt * disk[disk_id].block_size > comm_size) {
    326342                                retval = ELIMIT;
    327343                                break;
     
    330346                        break;
    331347                case BD_GET_BLOCK_SIZE:
    332                         async_answer_1(callid, EOK, block_size);
     348                        async_answer_1(callid, EOK, disk[disk_id].block_size);
    333349                        continue;
    334350                case BD_GET_NUM_BLOCKS:
     
    353369        identify_data_t idata;
    354370        uint8_t model[40];
     371        ata_inquiry_data_t inq_data;
    355372        uint16_t w;
    356373        uint8_t c;
     
    359376        unsigned i;
    360377
     378        d->present = false;
     379        fibril_mutex_initialize(&d->lock);
     380
     381        /* Try identify command. */
    361382        rc = drive_identify(disk_id, &idata);
    362         if (rc != EOK) {
    363                 d->present = false;
    364                 return rc;
    365         }
    366 
    367         if ((idata.caps & cap_lba) == 0) {
     383        if (rc == EOK) {
     384                /* Success. It's a register (non-packet) device. */
     385                printf("ATA register-only device found.\n");
     386                d->dev_type = ata_reg_dev;
     387        } else if (rc == EIO) {
     388                /*
     389                 * There is something, but not a register device.
     390                 * It could be a packet device.
     391                 */
     392                rc = identify_pkt_dev(disk_id, &idata);
     393                if (rc == EOK) {
     394                        /* We have a packet device. */
     395                        d->dev_type = ata_pkt_dev;
     396                } else {
     397                        /* Nope. Something's there, but not recognized. */
     398                        return EIO;
     399                }
     400        } else {
     401                /* Operation timed out. That means there is no device there. */
     402                return EIO;
     403        }
     404
     405        printf("device caps: 0x%04x\n", idata.caps);
     406        if (d->dev_type == ata_pkt_dev) {
     407                /* Packet device */
     408                d->amode = 0;
     409
     410                d->geom.cylinders = 0;
     411                d->geom.heads = 0;
     412                d->geom.sectors = 0;
     413
     414                d->blocks = 0;
     415        } else if ((idata.caps & rd_cap_lba) == 0) {
    368416                /* Device only supports CHS addressing. */
    369417                d->amode = am_chs;
     
    422470        d->model[pos] = '\0';
    423471
     472        if (d->dev_type == ata_pkt_dev) {
     473                /* Send inquiry. */
     474                rc = ata_pcmd_inquiry(0, &inq_data, sizeof(inq_data));
     475                if (rc != EOK) {
     476                        printf("Device inquiry failed.\n");
     477                        d->present = false;
     478                        return EIO;
     479                }
     480
     481                /* Check device type. */
     482                if (INQUIRY_PDEV_TYPE(inq_data.pdev_type) != PDEV_TYPE_CDROM)
     483                        printf("Warning: Peripheral device type is not CD-ROM.\n");
     484
     485                /* Assume 2k block size for now. */
     486                d->block_size = 2048;
     487        } else {
     488                /* Assume register Read always uses 512-byte blocks. */
     489                d->block_size = 512;
     490        }
     491
    424492        d->present = true;
    425         fibril_mutex_initialize(&d->lock);
    426 
    427493        return EOK;
    428494}
     
    435501
    436502        while (cnt > 0) {
    437                 rc = ata_bd_read_block(disk_id, ba, 1, buf);
     503                if (disk[disk_id].dev_type == ata_reg_dev)
     504                        rc = ata_rcmd_read(disk_id, ba, 1, buf);
     505                else
     506                        rc = ata_pcmd_read_12(disk_id, ba, 1, buf,
     507                            disk[disk_id].block_size);
     508
    438509                if (rc != EOK)
    439510                        return rc;
     
    441512                ++ba;
    442513                --cnt;
    443                 buf += block_size;
     514                buf += disk[disk_id].block_size;
    444515        }
    445516
     
    453524        int rc;
    454525
     526        if (disk[disk_id].dev_type != ata_reg_dev)
     527                return ENOTSUP;
     528
    455529        while (cnt > 0) {
    456                 rc = ata_bd_write_block(disk_id, ba, 1, buf);
     530                rc = ata_rcmd_write(disk_id, ba, 1, buf);
    457531                if (rc != EOK)
    458532                        return rc;
     
    460534                ++ba;
    461535                --cnt;
    462                 buf += block_size;
     536                buf += disk[disk_id].block_size;
    463537        }
    464538
     
    473547 * @param disk_id       Device ID, 0 or 1.
    474548 * @param buf           Pointer to a 512-byte buffer.
     549 *
     550 * @return              ETIMEOUT on timeout (this can mean the device is
     551 *                      not present). EIO if device responds with error.
    475552 */
    476553static int drive_identify(int disk_id, void *buf)
     
    484561
    485562        if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
    486                 return EIO;
     563                return ETIMEOUT;
    487564
    488565        pio_write_8(&cmd->drive_head, drv_head);
     
    493570         */
    494571        if (wait_status(SR_DRDY, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
    495                 return EIO;
     572                return ETIMEOUT;
    496573
    497574        pio_write_8(&cmd->command, CMD_IDENTIFY_DRIVE);
    498575
    499576        if (wait_status(0, ~SR_BSY, &status, TIMEOUT_PROBE) != EOK)
    500                 return EIO;
     577                return ETIMEOUT;
    501578
    502579        /* Read data from the disk buffer. */
    503580
    504581        if ((status & SR_DRQ) != 0) {
    505                 for (i = 0; i < block_size / 2; i++) {
     582                for (i = 0; i < identify_data_size / 2; i++) {
    506583                        data = pio_read_16(&cmd->data_port);
    507584                        ((uint16_t *) buf)[i] = data;
     
    509586        }
    510587
     588        if ((status & SR_ERR) != 0) {
     589                return EIO;
     590        }
     591
     592        return EOK;
     593}
     594
     595/** Issue Identify Packet Device command.
     596 *
     597 * Reads @c identify data into the provided buffer. This is used to detect
     598 * whether an ATAPI device is present and if so, to determine its parameters.
     599 *
     600 * @param dev_idx       Device index, 0 or 1.
     601 * @param buf           Pointer to a 512-byte buffer.
     602 */
     603static int identify_pkt_dev(int dev_idx, void *buf)
     604{
     605        uint16_t data;
     606        uint8_t status;
     607        uint8_t drv_head;
     608        size_t i;
     609
     610        drv_head = ((dev_idx != 0) ? DHR_DRV : 0);
     611
     612        if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
     613                return EIO;
     614
     615        pio_write_8(&cmd->drive_head, drv_head);
     616
     617        /* For ATAPI commands we do not need to wait for DRDY. */
     618        if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
     619                return EIO;
     620
     621        pio_write_8(&cmd->command, CMD_IDENTIFY_PKT_DEV);
     622
     623        if (wait_status(0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK)
     624                return EIO;
     625
     626        /* Read data from the device buffer. */
     627
     628        if ((status & SR_DRQ) != 0) {
     629                for (i = 0; i < identify_data_size / 2; i++) {
     630                        data = pio_read_16(&cmd->data_port);
     631                        ((uint16_t *) buf)[i] = data;
     632                }
     633        }
     634
    511635        if ((status & SR_ERR) != 0)
    512636                return EIO;
     637
     638        return EOK;
     639}
     640
     641/** Issue packet command (i. e. write a command packet to the device).
     642 *
     643 * Only data-in commands are supported (e.g. inquiry, read).
     644 *
     645 * @param dev_idx       Device index (0 or 1)
     646 * @param obuf          Buffer for storing data read from device
     647 * @param obuf_size     Size of obuf in bytes
     648 *
     649 * @return EOK on success, EIO on error.
     650 */
     651static int ata_cmd_packet(int dev_idx, const void *cpkt, size_t cpkt_size,
     652    void *obuf, size_t obuf_size)
     653{
     654        size_t i;
     655        uint8_t status;
     656        uint8_t drv_head;
     657        disk_t *d;
     658        size_t data_size;
     659        uint16_t val;
     660
     661        d = &disk[dev_idx];
     662        fibril_mutex_lock(&d->lock);
     663
     664        /* New value for Drive/Head register */
     665        drv_head =
     666            ((dev_idx != 0) ? DHR_DRV : 0);
     667
     668        if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) {
     669                fibril_mutex_unlock(&d->lock);
     670                return EIO;
     671        }
     672
     673        pio_write_8(&cmd->drive_head, drv_head);
     674
     675        if (wait_status(0, ~(SR_BSY|SR_DRQ), NULL, TIMEOUT_BSY) != EOK) {
     676                fibril_mutex_unlock(&d->lock);
     677                return EIO;
     678        }
     679
     680        /* Byte count <- max. number of bytes we can read in one transfer. */
     681        pio_write_8(&cmd->cylinder_low, 0xfe);
     682        pio_write_8(&cmd->cylinder_high, 0xff);
     683
     684        pio_write_8(&cmd->command, CMD_PACKET);
     685
     686        if (wait_status(SR_DRQ, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) {
     687                fibril_mutex_unlock(&d->lock);
     688                return EIO;
     689        }
     690
     691        /* Write command packet. */
     692        for (i = 0; i < (cpkt_size + 1) / 2; i++)
     693                pio_write_16(&cmd->data_port, ((uint16_t *) cpkt)[i]);
     694
     695        if (wait_status(0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) {
     696                fibril_mutex_unlock(&d->lock);
     697                return EIO;
     698        }
     699
     700        if ((status & SR_DRQ) == 0) {
     701                fibril_mutex_unlock(&d->lock);
     702                return EIO;
     703        }
     704
     705        /* Read byte count. */
     706        data_size = (uint16_t) pio_read_8(&cmd->cylinder_low) +
     707            ((uint16_t) pio_read_8(&cmd->cylinder_high) << 8);
     708
     709        /* Check whether data fits into output buffer. */
     710        if (data_size > obuf_size) {
     711                /* Output buffer is too small to store data. */
     712                fibril_mutex_unlock(&d->lock);
     713                return EIO;
     714        }
     715
     716        /* Read data from the device buffer. */
     717        for (i = 0; i < (data_size + 1) / 2; i++) {
     718                val = pio_read_16(&cmd->data_port);
     719                ((uint16_t *) obuf)[i] = val;
     720        }
     721
     722        if (status & SR_ERR) {
     723                fibril_mutex_unlock(&d->lock);
     724                return EIO;
     725        }
     726
     727        fibril_mutex_unlock(&d->lock);
     728
     729        return EOK;
     730}
     731
     732/** Issue ATAPI Inquiry.
     733 *
     734 * @param dev_idx       Device index (0 or 1)
     735 * @param obuf          Buffer for storing inquiry data read from device
     736 * @param obuf_size     Size of obuf in bytes
     737 *
     738 * @return EOK on success, EIO on error.
     739 */
     740static int ata_pcmd_inquiry(int dev_idx, void *obuf, size_t obuf_size)
     741{
     742        ata_pcmd_inquiry_t cp;
     743        int rc;
     744
     745        memset(&cp, 0, sizeof(cp));
     746
     747        cp.opcode = PCMD_INQUIRY;
     748        cp.alloc_len = min(obuf_size, 0xff); /* Allocation length */
     749
     750        rc = ata_cmd_packet(0, &cp, sizeof(cp), obuf, obuf_size);
     751        if (rc != EOK)
     752                return rc;
     753
     754        return EOK;
     755}
     756
     757/** Issue ATAPI read(12) command.
     758 *
     759 * Output buffer must be large enough to hold the data, otherwise the
     760 * function will fail.
     761 *
     762 * @param dev_idx       Device index (0 or 1)
     763 * @param ba            Starting block address
     764 * @param cnt           Number of blocks to read
     765 * @param obuf          Buffer for storing inquiry data read from device
     766 * @param obuf_size     Size of obuf in bytes
     767 *
     768 * @return EOK on success, EIO on error.
     769 */
     770static int ata_pcmd_read_12(int dev_idx, uint64_t ba, size_t cnt,
     771    void *obuf, size_t obuf_size)
     772{
     773        ata_pcmd_read_12_t cp;
     774        int rc;
     775
     776        if (ba > UINT32_MAX)
     777                return EINVAL;
     778
     779        memset(&cp, 0, sizeof(cp));
     780
     781        cp.opcode = PCMD_READ_12;
     782        cp.ba = host2uint32_t_be(ba);
     783        cp.nblocks = host2uint32_t_be(cnt);
     784
     785        rc = ata_cmd_packet(0, &cp, sizeof(cp), obuf, obuf_size);
     786        if (rc != EOK)
     787                return rc;
    513788
    514789        return EOK;
     
    524799 * @return EOK on success, EIO on error.
    525800 */
    526 static int ata_bd_read_block(int disk_id, uint64_t ba, size_t blk_cnt,
     801static int ata_rcmd_read(int disk_id, uint64_t ba, size_t blk_cnt,
    527802    void *buf)
    528803{
     
    579854                /* Read data from the device buffer. */
    580855
    581                 for (i = 0; i < block_size / 2; i++) {
     856                for (i = 0; i < disk[disk_id].block_size / 2; i++) {
    582857                        data = pio_read_16(&cmd->data_port);
    583858                        ((uint16_t *) buf)[i] = data;
     
    601876 * @return EOK on success, EIO on error.
    602877 */
    603 static int ata_bd_write_block(int disk_id, uint64_t ba, size_t cnt,
     878static int ata_rcmd_write(int disk_id, uint64_t ba, size_t cnt,
    604879    const void *buf)
    605880{
     
    655930                /* Write data to the device buffer. */
    656931
    657                 for (i = 0; i < block_size / 2; i++) {
     932                for (i = 0; i < disk[disk_id].block_size / 2; i++) {
    658933                        pio_write_16(&cmd->data_port, ((uint16_t *) buf)[i]);
    659934                }
  • uspace/srv/bd/ata_bd/ata_bd.h

    r5716e9a r76b5a95c  
    5353};
    5454
    55 /** Block addressing mode. */
    56 enum addr_mode {
     55enum ata_dev_type {
     56        ata_reg_dev,    /* Register device (no packet feature set support) */
     57        ata_pkt_dev     /* Packet device (supports packet feature set). */
     58};
     59
     60/** Register device block addressing mode. */
     61enum rd_addr_mode {
    5762        am_chs,         /**< CHS block addressing */
    5863        am_lba28,       /**< LBA-28 block addressing */
     
    6267/** Block coordinates */
    6368typedef struct {
    64         /** Addressing mode used */
    65         enum addr_mode amode;
     69        enum rd_addr_mode amode;
    6670
    6771        union {
     
    9094typedef struct {
    9195        bool present;
    92         enum addr_mode amode;
     96
     97        /** Device type */
     98        enum ata_dev_type dev_type;
     99
     100        /** Addressing mode to use (if register device) */
     101        enum rd_addr_mode amode;
    93102
    94103        /*
     
    102111
    103112        uint64_t blocks;
     113        size_t block_size;
    104114
    105115        char model[STR_BOUNDS(40) + 1];
  • uspace/srv/bd/ata_bd/ata_hw.h

    r5716e9a r76b5a95c  
    134134        CMD_WRITE_SECTORS       = 0x30,
    135135        CMD_WRITE_SECTORS_EXT   = 0x34,
     136        CMD_PACKET              = 0xA0,
     137        CMD_IDENTIFY_PKT_DEV    = 0xA1,
    136138        CMD_IDENTIFY_DRIVE      = 0xEC
    137139};
    138140
    139 /** Data returned from @c identify command. */
     141/** Data returned from identify device and identify packet device command. */
    140142typedef struct {
    141143        uint16_t gen_conf;
     
    159161        uint16_t max_rw_multiple;
    160162        uint16_t _res48;
    161         uint16_t caps;
     163        uint16_t caps;          /* Different meaning for packet device */
    162164        uint16_t _res50;
    163165        uint16_t pio_timing;
     
    214216} identify_data_t;
    215217
    216 enum ata_caps {
    217         cap_iordy       = 0x0800,
    218         cap_iordy_cbd   = 0x0400,
    219         cap_lba         = 0x0200,
    220         cap_dma         = 0x0100
     218/** Capability bits for register device. */
     219enum ata_regdev_caps {
     220        rd_cap_iordy            = 0x0800,
     221        rd_cap_iordy_cbd        = 0x0400,
     222        rd_cap_lba              = 0x0200,
     223        rd_cap_dma              = 0x0100
     224};
     225
     226/** Capability bits for packet device. */
     227enum ata_pktdev_caps {
     228        pd_cap_ildma            = 0x8000,
     229        pd_cap_cmdqueue         = 0x4000,
     230        pd_cap_overlap          = 0x2000,
     231        pd_cap_need_softreset   = 0x1000,       /* Obsolete (ATAPI-6) */
     232        pd_cap_iordy            = 0x0800,
     233        pd_cap_iordy_dis        = 0x0400,
     234        pd_cap_lba              = 0x0200,       /* Must be on */
     235        pd_cap_dma              = 0x0100
    221236};
    222237
     
    226241};
    227242
     243/** ATA packet command codes. */
     244enum ata_pkt_command {
     245        PCMD_INQUIRY            = 0x12,
     246        PCMD_READ_12            = 0xa8
     247};
     248
     249/** ATAPI Inquiry command */
     250typedef struct {
     251        uint8_t opcode;         /**< Operation code (PCMD_INQUIRY) */
     252        uint8_t _res0;
     253        uint8_t _res1;
     254        uint8_t _res2;
     255        uint8_t alloc_len;      /**< Allocation length */
     256        uint8_t _res3;
     257        uint8_t _res4;
     258        uint8_t _res5;
     259        uint32_t _res6;
     260} __attribute__ ((packed)) ata_pcmd_inquiry_t;
     261
     262/** ATAPI Read(12) command */
     263typedef struct {
     264        uint8_t opcode;         /**< Operation code (PCMD_READ_12) */
     265        uint8_t _res0;
     266        uint32_t ba;            /**< Starting block address */
     267        uint32_t nblocks;       /**< Number of blocks to transfer */
     268        uint8_t _res1;
     269        uint8_t _res2;
     270} __attribute__ ((packed)) ata_pcmd_read_12_t;
     271
     272/** Data returned from Inquiry command (mandatory part) */
     273typedef struct {
     274        uint8_t pdev_type;      /** Reserved, Peripheral device type */
     275        uint8_t rmb;            /** RMB, Reserved */
     276        uint8_t std_version;    /** ISO version, ECMA version, ANSI version */
     277        uint8_t atapi_ver_rdf;  /** ATAPI version, Response data format */
     278        uint8_t additional_len; /** Additional length */
     279        uint8_t _res0;
     280        uint8_t _res1;
     281        uint8_t _res2;
     282        uint8_t vendor_id[8];   /** Vendor ID */
     283        uint8_t product_id[8];  /** Product ID */
     284        uint8_t product_rev[4]; /** Product revision level */
     285} ata_inquiry_data_t;
     286
     287/** Extract value of ata_inquiry_data_t.pdev_type */
     288#define INQUIRY_PDEV_TYPE(val) ((val) & 0x1f)
     289
     290/** Values for ata_inquiry_data_t.pdev_type */
     291enum ata_pdev_type {
     292        PDEV_TYPE_CDROM         = 0x05
     293};
     294
    228295#endif
    229296
  • uspace/srv/devman/devman.c

    r5716e9a r76b5a95c  
    4141#include "devman.h"
    4242
     43fun_node_t *find_node_child(fun_node_t *parent, const char *name);
     44
    4345/* hash table operations */
    4446
     
    5153    link_t *item)
    5254{
    53         node_t *dev = hash_table_get_instance(item, node_t, devman_link);
     55        dev_node_t *dev = hash_table_get_instance(item, dev_node_t, devman_dev);
    5456        return (dev->handle == (devman_handle_t) key[0]);
    5557}
    5658
    57 static int devmap_devices_compare(unsigned long key[], hash_count_t keys,
     59static int devman_functions_compare(unsigned long key[], hash_count_t keys,
    5860    link_t *item)
    5961{
    60         node_t *dev = hash_table_get_instance(item, node_t, devmap_link);
    61         return (dev->devmap_handle == (devmap_handle_t) key[0]);
     62        fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devman_fun);
     63        return (fun->handle == (devman_handle_t) key[0]);
     64}
     65
     66static int devmap_functions_compare(unsigned long key[], hash_count_t keys,
     67    link_t *item)
     68{
     69        fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devmap_fun);
     70        return (fun->devmap_handle == (devmap_handle_t) key[0]);
    6271}
    6372
     
    8291};
    8392
     93static hash_table_operations_t devman_functions_ops = {
     94        .hash = devices_hash,
     95        .compare = devman_functions_compare,
     96        .remove_callback = devices_remove_callback
     97};
     98
    8499static hash_table_operations_t devmap_devices_ops = {
    85100        .hash = devices_hash,
    86         .compare = devmap_devices_compare,
     101        .compare = devmap_functions_compare,
    87102        .remove_callback = devices_remove_callback
    88103};
     
    373388}
    374389
    375 /** Create root device node in the device tree.
     390/** Create root device and function node in the device tree.
    376391 *
    377392 * @param tree  The device tree.
    378393 * @return      True on success, false otherwise.
    379394 */
    380 bool create_root_node(dev_tree_t *tree)
    381 {
    382         node_t *node;
    383 
    384         printf(NAME ": create_root_node\n");
    385 
     395bool create_root_nodes(dev_tree_t *tree)
     396{
     397        fun_node_t *fun;
     398        dev_node_t *dev;
     399       
     400        printf(NAME ": create_root_nodes\n");
     401       
    386402        fibril_rwlock_write_lock(&tree->rwlock);
    387         node = create_dev_node();
    388         if (node != NULL) {
    389                 insert_dev_node(tree, node, clone_string(""), NULL);
    390                 match_id_t *id = create_match_id();
    391                 id->id = clone_string("root");
    392                 id->score = 100;
    393                 add_match_id(&node->match_ids, id);
    394                 tree->root_node = node;
    395         }
     403       
     404        /*
     405         * Create root function. This is a pseudo function to which
     406         * the root device node is attached. It allows us to match
     407         * the root device driver in a standard manner, i.e. against
     408         * the parent function.
     409         */
     410       
     411        fun = create_fun_node();
     412        if (fun == NULL) {
     413                fibril_rwlock_write_unlock(&tree->rwlock);
     414                return false;
     415        }
     416       
     417        insert_fun_node(tree, fun, clone_string(""), NULL);
     418        match_id_t *id = create_match_id();
     419        id->id = clone_string("root");
     420        id->score = 100;
     421        add_match_id(&fun->match_ids, id);
     422        tree->root_node = fun;
     423       
     424        /*
     425         * Create root device node.
     426         */
     427        dev = create_dev_node();
     428        if (dev == NULL) {
     429                fibril_rwlock_write_unlock(&tree->rwlock);
     430                return false;
     431        }
     432       
     433        insert_dev_node(tree, dev, fun);
     434       
    396435        fibril_rwlock_write_unlock(&tree->rwlock);
    397 
    398         return node != NULL;
     436       
     437        return dev != NULL;
    399438}
    400439
     
    414453 *                      is found.
    415454 */
    416 driver_t *find_best_match_driver(driver_list_t *drivers_list, node_t *node)
     455driver_t *find_best_match_driver(driver_list_t *drivers_list, dev_node_t *node)
    417456{
    418457        driver_t *best_drv = NULL, *drv = NULL;
     
    442481 * @param drv           The driver.
    443482 */
    444 void attach_driver(node_t *node, driver_t *drv)
     483void attach_driver(dev_node_t *dev, driver_t *drv)
    445484{
    446485        printf(NAME ": attach_driver %s to device %s\n",
    447             drv->name, node->pathname);
     486            drv->name, dev->pfun->pathname);
    448487       
    449488        fibril_mutex_lock(&drv->driver_mutex);
    450489       
    451         node->drv = drv;
    452         list_append(&node->driver_devices, &drv->devices);
     490        dev->drv = drv;
     491        list_append(&dev->driver_devices, &drv->devices);
    453492       
    454493        fibril_mutex_unlock(&drv->driver_mutex);
     
    530569static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree)
    531570{
    532         node_t *dev;
     571        dev_node_t *dev;
    533572        link_t *link;
    534573        int phone;
     
    551590        link = driver->devices.next;
    552591        while (link != &driver->devices) {
    553                 dev = list_get_instance(link, node_t, driver_devices);
     592                dev = list_get_instance(link, dev_node_t, driver_devices);
    554593                if (dev->passed_to_driver) {
    555594                        link = link->next;
     
    669708}
    670709
    671 /** Create devmap path and name for the device. */
    672 static void devmap_register_tree_device(node_t *node, dev_tree_t *tree)
     710/** Create devmap path and name for the function. */
     711void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
    673712{
    674713        char *devmap_pathname = NULL;
    675714        char *devmap_name = NULL;
    676715       
    677         asprintf(&devmap_name, "%s", node->pathname);
     716        asprintf(&devmap_name, "%s", fun->pathname);
    678717        if (devmap_name == NULL)
    679718                return;
     
    689728       
    690729        devmap_device_register_with_iface(devmap_pathname,
    691             &node->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    692        
    693         tree_add_devmap_device(tree, node);
     730            &fun->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
     731       
     732        tree_add_devmap_function(tree, fun);
    694733       
    695734        free(devmap_name);
     
    702741 * @param node          The device's node in the device tree.
    703742 */
    704 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree)
     743void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
    705744{
    706745        /*
     
    709748         */
    710749        printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
    711             node->name);
     750            dev->pfun->name);
    712751       
    713752        sysarg_t rc;
     
    716755        /* Send the device to the driver. */
    717756        devman_handle_t parent_handle;
    718         if (node->parent) {
    719                 parent_handle = node->parent->handle;
     757        if (dev->pfun) {
     758                parent_handle = dev->pfun->handle;
    720759        } else {
    721760                parent_handle = 0;
    722761        }
    723762
    724         aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle,
     763        aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle,
    725764            parent_handle, &answer);
    726765       
    727766        /* Send the device's name to the driver. */
    728         rc = async_data_write_start(phone, node->name,
    729             str_size(node->name) + 1);
     767        rc = async_data_write_start(phone, dev->pfun->name,
     768            str_size(dev->pfun->name) + 1);
    730769        if (rc != EOK) {
    731770                /* TODO handle error */
     
    737776        switch(rc) {
    738777        case EOK:
    739                 node->state = DEVICE_USABLE;
    740                 devmap_register_tree_device(node, tree);
     778                dev->state = DEVICE_USABLE;
    741779                break;
    742780        case ENOENT:
    743                 node->state = DEVICE_NOT_PRESENT;
     781                dev->state = DEVICE_NOT_PRESENT;
    744782                break;
    745783        default:
    746                 node->state = DEVICE_INVALID;
    747         }
    748        
    749         node->passed_to_driver = true;
     784                dev->state = DEVICE_INVALID;
     785        }
     786       
     787        dev->passed_to_driver = true;
    750788
    751789        return;
     
    759797 *                      successfully assigned to the device, false otherwise.
    760798 */
    761 bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree)
    762 {
     799bool assign_driver(dev_node_t *dev, driver_list_t *drivers_list,
     800    dev_tree_t *tree)
     801{
     802        assert(dev != NULL);
     803        assert(drivers_list != NULL);
     804        assert(tree != NULL);
     805       
    763806        /*
    764807         * Find the driver which is the most suitable for handling this device.
    765808         */
    766         driver_t *drv = find_best_match_driver(drivers_list, node);
     809        driver_t *drv = find_best_match_driver(drivers_list, dev);
    767810        if (drv == NULL) {
    768811                printf(NAME ": no driver found for device '%s'.\n",
    769                     node->pathname);
     812                    dev->pfun->pathname);
    770813                return false;
    771814        }
    772815       
    773816        /* Attach the driver to the device. */
    774         attach_driver(node, drv);
     817        attach_driver(dev, drv);
    775818       
    776819        fibril_mutex_lock(&drv->driver_mutex);
     
    786829                int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    787830                if (phone >= 0) {
    788                         add_device(phone, drv, node, tree);
     831                        add_device(phone, drv, dev, tree);
    789832                        async_hangup(phone);
    790833                }
     
    810853        hash_table_create(&tree->devman_devices, DEVICE_BUCKETS, 1,
    811854            &devman_devices_ops);
    812         hash_table_create(&tree->devmap_devices, DEVICE_BUCKETS, 1,
     855        hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1,
     856            &devman_functions_ops);
     857        hash_table_create(&tree->devmap_functions, DEVICE_BUCKETS, 1,
    813858            &devmap_devices_ops);
    814859       
    815860        fibril_rwlock_initialize(&tree->rwlock);
    816861       
    817         /* Create root node and add it to the device tree. */
    818         if (!create_root_node(tree))
     862        /* Create root function and root device and add them to the device tree. */
     863        if (!create_root_nodes(tree))
    819864                return false;
    820865
    821866        /* Find suitable driver and start it. */
    822         return assign_driver(tree->root_node, drivers_list, tree);
     867        return assign_driver(tree->root_node->child, drivers_list, tree);
    823868}
    824869
     
    829874 * @return              A device node structure.
    830875 */
    831 node_t *create_dev_node(void)
    832 {
    833         node_t *res = malloc(sizeof(node_t));
     876dev_node_t *create_dev_node(void)
     877{
     878        dev_node_t *res = malloc(sizeof(dev_node_t));
    834879       
    835880        if (res != NULL) {
    836                 memset(res, 0, sizeof(node_t));
    837                 list_initialize(&res->children);
    838                 list_initialize(&res->match_ids.ids);
    839                 list_initialize(&res->classes);
     881                memset(res, 0, sizeof(dev_node_t));
     882                list_initialize(&res->functions);
     883                link_initialize(&res->driver_devices);
     884                link_initialize(&res->devman_dev);
    840885        }
    841886       
     
    847892 * @param node          The device node structure.
    848893 */
    849 void delete_dev_node(node_t *node)
    850 {
    851         assert(list_empty(&node->children));
    852         assert(node->parent == NULL);
    853         assert(node->drv == NULL);
    854        
    855         clean_match_ids(&node->match_ids);
    856         free_not_null(node->name);
    857         free_not_null(node->pathname);
    858         free(node);
     894void delete_dev_node(dev_node_t *dev)
     895{
     896        assert(list_empty(&dev->functions));
     897        assert(dev->pfun == NULL);
     898        assert(dev->drv == NULL);
     899       
     900        free(dev);
    859901}
    860902
     
    865907 * @return              The device node.
    866908 */
    867 node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
     909dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    868910{
    869911        unsigned long key = handle;
     
    873915       
    874916        link = hash_table_find(&tree->devman_devices, &key);
    875         return hash_table_get_instance(link, node_t, devman_link);
     917        return hash_table_get_instance(link, dev_node_t, devman_dev);
    876918}
    877919
     
    882924 * @return              The device node.
    883925 */
    884 node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)
    885 {
    886         node_t *node = NULL;
     926dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)
     927{
     928        dev_node_t *dev = NULL;
    887929       
    888930        fibril_rwlock_read_lock(&tree->rwlock);
    889         node = find_dev_node_no_lock(tree, handle);
     931        dev = find_dev_node_no_lock(tree, handle);
    890932        fibril_rwlock_read_unlock(&tree->rwlock);
    891933       
    892         return node;
    893 }
    894 
     934        return dev;
     935}
     936
     937/* Function nodes */
     938
     939/** Create a new function node.
     940 *
     941 * @return              A function node structure.
     942 */
     943fun_node_t *create_fun_node(void)
     944{
     945        fun_node_t *res = malloc(sizeof(fun_node_t));
     946       
     947        if (res != NULL) {
     948                memset(res, 0, sizeof(fun_node_t));
     949                link_initialize(&res->dev_functions);
     950                list_initialize(&res->match_ids.ids);
     951                list_initialize(&res->classes);
     952                link_initialize(&res->devman_fun);
     953                link_initialize(&res->devmap_fun);
     954        }
     955       
     956        return res;
     957}
     958
     959/** Delete a function node.
     960 *
     961 * @param fun           The device node structure.
     962 */
     963void delete_fun_node(fun_node_t *fun)
     964{
     965        assert(fun->dev == NULL);
     966        assert(fun->child == NULL);
     967       
     968        clean_match_ids(&fun->match_ids);
     969        free_not_null(fun->name);
     970        free_not_null(fun->pathname);
     971        free(fun);
     972}
     973
     974/** Find the function node with the specified handle.
     975 *
     976 * @param tree          The device tree where we look for the device node.
     977 * @param handle        The handle of the function.
     978 * @return              The function node.
     979 */
     980fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
     981{
     982        unsigned long key = handle;
     983        link_t *link;
     984       
     985        assert(fibril_rwlock_is_locked(&tree->rwlock));
     986       
     987        link = hash_table_find(&tree->devman_functions, &key);
     988        if (link == NULL)
     989                return NULL;
     990       
     991        return hash_table_get_instance(link, fun_node_t, devman_fun);
     992}
     993
     994/** Find the function node with the specified handle.
     995 *
     996 * @param tree          The device tree where we look for the device node.
     997 * @param handle        The handle of the function.
     998 * @return              The function node.
     999 */
     1000fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle)
     1001{
     1002        fun_node_t *fun = NULL;
     1003       
     1004        fibril_rwlock_read_lock(&tree->rwlock);
     1005        fun = find_fun_node_no_lock(tree, handle);
     1006        fibril_rwlock_read_unlock(&tree->rwlock);
     1007       
     1008        return fun;
     1009}
    8951010
    8961011/** Create and set device's full path in device tree.
     
    9011016 *                      resources etc.).
    9021017 */
    903 static bool set_dev_path(node_t *node, node_t *parent)
    904 {
    905         assert(node->name != NULL);
    906        
    907         size_t pathsize = (str_size(node->name) + 1);
     1018static bool set_fun_path(fun_node_t *fun, fun_node_t *parent)
     1019{
     1020        assert(fun->name != NULL);
     1021       
     1022        size_t pathsize = (str_size(fun->name) + 1);
    9081023        if (parent != NULL)
    9091024                pathsize += str_size(parent->pathname) + 1;
    9101025       
    911         node->pathname = (char *) malloc(pathsize);
    912         if (node->pathname == NULL) {
     1026        fun->pathname = (char *) malloc(pathsize);
     1027        if (fun->pathname == NULL) {
    9131028                printf(NAME ": failed to allocate device path.\n");
    9141029                return false;
     
    9161031       
    9171032        if (parent != NULL) {
    918                 str_cpy(node->pathname, pathsize, parent->pathname);
    919                 str_append(node->pathname, pathsize, "/");
    920                 str_append(node->pathname, pathsize, node->name);
     1033                str_cpy(fun->pathname, pathsize, parent->pathname);
     1034                str_append(fun->pathname, pathsize, "/");
     1035                str_append(fun->pathname, pathsize, fun->name);
    9211036        } else {
    922                 str_cpy(node->pathname, pathsize, node->name);
     1037                str_cpy(fun->pathname, pathsize, fun->name);
    9231038        }
    9241039       
     
    9361051 *                      etc.).
    9371052 */
    938 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name,
    939     node_t *parent)
    940 {
    941         assert(node != NULL);
     1053bool insert_dev_node(dev_tree_t *tree, dev_node_t *dev, fun_node_t *pfun)
     1054{
     1055        assert(dev != NULL);
    9421056        assert(tree != NULL);
    943         assert(dev_name != NULL);
    9441057        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    9451058       
    946         node->name = dev_name;
    947         if (!set_dev_path(node, parent)) {
     1059        /* Add the node to the handle-to-node map. */
     1060        dev->handle = ++tree->current_handle;
     1061        unsigned long key = dev->handle;
     1062        hash_table_insert(&tree->devman_devices, &key, &dev->devman_dev);
     1063
     1064        /* Add the node to the list of its parent's children. */
     1065        printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
     1066        dev->pfun = pfun;
     1067        pfun->child = dev;
     1068       
     1069        return true;
     1070}
     1071
     1072/** Insert new function into device tree.
     1073 *
     1074 * @param tree          The device tree.
     1075 * @param node          The newly added function node.
     1076 * @param dev_name      The name of the newly added function.
     1077 * @param parent        Owning device node.
     1078 *
     1079 * @return              True on success, false otherwise (insufficient resources
     1080 *                      etc.).
     1081 */
     1082bool insert_fun_node(dev_tree_t *tree, fun_node_t *fun, char *fun_name,
     1083    dev_node_t *dev)
     1084{
     1085        fun_node_t *pfun;
     1086       
     1087        assert(fun != NULL);
     1088        assert(tree != NULL);
     1089        assert(fun_name != NULL);
     1090        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
     1091       
     1092        /*
     1093         * The root function is a special case, it does not belong to any
     1094         * device so for the root function dev == NULL.
     1095         */
     1096        pfun = (dev != NULL) ? dev->pfun : NULL;
     1097       
     1098        fun->name = fun_name;
     1099        if (!set_fun_path(fun, pfun)) {
    9481100                return false;
    9491101        }
    9501102       
    9511103        /* Add the node to the handle-to-node map. */
    952         node->handle = ++tree->current_handle;
    953         unsigned long key = node->handle;
    954         hash_table_insert(&tree->devman_devices, &key, &node->devman_link);
     1104        fun->handle = ++tree->current_handle;
     1105        unsigned long key = fun->handle;
     1106        hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun);
    9551107
    9561108        /* Add the node to the list of its parent's children. */
    957         node->parent = parent;
    958         if (parent != NULL)
    959                 list_append(&node->sibling, &parent->children);
     1109        fun->dev = dev;
     1110        if (dev != NULL)
     1111                list_append(&fun->dev_functions, &dev->functions);
    9601112       
    9611113        return true;
    9621114}
    9631115
    964 /** Find device node with a specified path in the device tree.
     1116/** Find function node with a specified path in the device tree.
    9651117 *
    966  * @param path          The path of the device node in the device tree.
     1118 * @param path          The path of the function node in the device tree.
    9671119 * @param tree          The device tree.
    968  * @return              The device node if it is present in the tree, NULL
     1120 * @return              The function node if it is present in the tree, NULL
    9691121 *                      otherwise.
    9701122 */
    971 node_t *find_dev_node_by_path(dev_tree_t *tree, char *path)
     1123fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path)
    9721124{
    9731125        fibril_rwlock_read_lock(&tree->rwlock);
    9741126       
    975         node_t *dev = tree->root_node;
     1127        fun_node_t *fun = tree->root_node;
    9761128        /*
    977          * Relative path to the device from its parent (but with '/' at the
     1129         * Relative path to the function from its parent (but with '/' at the
    9781130         * beginning)
    9791131         */
     
    9821134        bool cont = (rel_path[0] == '/');
    9831135       
    984         while (cont && dev != NULL) {
     1136        while (cont && fun != NULL) {
    9851137                next_path_elem  = get_path_elem_end(rel_path + 1);
    9861138                if (next_path_elem[0] == '/') {
     
    9911143                }
    9921144               
    993                 dev = find_node_child(dev, rel_path + 1);
     1145                fun = find_node_child(fun, rel_path + 1);
    9941146               
    9951147                if (cont) {
     
    10021154        fibril_rwlock_read_unlock(&tree->rwlock);
    10031155       
    1004         return dev;
    1005 }
    1006 
    1007 /** Find child device node with a specified name.
     1156        return fun;
     1157}
     1158
     1159/** Find child function node with a specified name.
    10081160 *
    10091161 * Device tree rwlock should be held at least for reading.
    10101162 *
    1011  * @param parent        The parent device node.
    1012  * @param name          The name of the child device node.
    1013  * @return              The child device node.
    1014  */
    1015 node_t *find_node_child(node_t *parent, const char *name)
    1016 {
    1017         node_t *dev;
     1163 * @param parent        The parent function node.
     1164 * @param name          The name of the child function.
     1165 * @return              The child function node.
     1166 */
     1167fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
     1168{
     1169        fun_node_t *fun;
    10181170        link_t *link;
    10191171       
    1020         link = parent->children.next;
    1021        
    1022         while (link != &parent->children) {
    1023                 dev = list_get_instance(link, node_t, sibling);
     1172        link = pfun->child->functions.next;
     1173       
     1174        while (link != &pfun->child->functions) {
     1175                fun = list_get_instance(link, fun_node_t, dev_functions);
    10241176               
    1025                 if (str_cmp(name, dev->name) == 0)
    1026                         return dev;
     1177                if (str_cmp(name, fun->name) == 0)
     1178                        return fun;
    10271179               
    10281180                link = link->next;
     
    11071259}
    11081260
    1109 /** Add the device to the class.
     1261/** Add the device function to the class.
    11101262 *
    11111263 * The device may be added to multiple classes and a class may contain multiple
     
    11201272 *                      with the class.
    11211273 */
    1122 dev_class_info_t *add_device_to_class(node_t *dev, dev_class_t *cl,
     1274dev_class_info_t *add_function_to_class(fun_node_t *fun, dev_class_t *cl,
    11231275    const char *base_dev_name)
    11241276{
    1125         dev_class_info_t *info = create_dev_class_info();
     1277        dev_class_info_t *info;
     1278
     1279        assert(fun != NULL);
     1280        assert(cl != NULL);
     1281
     1282        info = create_dev_class_info();
     1283
    11261284       
    11271285        if (info != NULL) {
    11281286                info->dev_class = cl;
    1129                 info->dev = dev;
     1287                info->fun = fun;
    11301288               
    11311289                /* Add the device to the class. */
     
    11351293               
    11361294                /* Add the class to the device. */
    1137                 list_append(&info->dev_classes, &dev->classes);
     1295                list_append(&info->dev_classes, &fun->classes);
    11381296               
    11391297                /* Create unique name for the device within the class. */
     
    11891347        list_initialize(&class_list->classes);
    11901348        fibril_rwlock_initialize(&class_list->rwlock);
    1191         hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1,
     1349        hash_table_create(&class_list->devmap_functions, DEVICE_BUCKETS, 1,
    11921350            &devmap_devices_class_ops);
    11931351}
     
    11961354/* Devmap devices */
    11971355
    1198 node_t *find_devmap_tree_device(dev_tree_t *tree, devmap_handle_t devmap_handle)
    1199 {
    1200         node_t *dev = NULL;
     1356fun_node_t *find_devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle)
     1357{
     1358        fun_node_t *fun = NULL;
    12011359        link_t *link;
    12021360        unsigned long key = (unsigned long) devmap_handle;
    12031361       
    12041362        fibril_rwlock_read_lock(&tree->rwlock);
    1205         link = hash_table_find(&tree->devmap_devices, &key);
     1363        link = hash_table_find(&tree->devmap_functions, &key);
    12061364        if (link != NULL)
    1207                 dev = hash_table_get_instance(link, node_t, devmap_link);
     1365                fun = hash_table_get_instance(link, fun_node_t, devmap_fun);
    12081366        fibril_rwlock_read_unlock(&tree->rwlock);
    12091367       
    1210         return dev;
    1211 }
    1212 
    1213 node_t *find_devmap_class_device(class_list_t *classes,
     1368        return fun;
     1369}
     1370
     1371fun_node_t *find_devmap_class_function(class_list_t *classes,
    12141372    devmap_handle_t devmap_handle)
    12151373{
    1216         node_t *dev = NULL;
     1374        fun_node_t *fun = NULL;
    12171375        dev_class_info_t *cli;
    12181376        link_t *link;
     
    12201378       
    12211379        fibril_rwlock_read_lock(&classes->rwlock);
    1222         link = hash_table_find(&classes->devmap_devices, &key);
     1380        link = hash_table_find(&classes->devmap_functions, &key);
    12231381        if (link != NULL) {
    12241382                cli = hash_table_get_instance(link, dev_class_info_t,
    12251383                    devmap_link);
    1226                 dev = cli->dev;
     1384                fun = cli->fun;
    12271385        }
    12281386        fibril_rwlock_read_unlock(&classes->rwlock);
    12291387       
    1230         return dev;
    1231 }
    1232 
    1233 void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
     1388        return fun;
     1389}
     1390
     1391void class_add_devmap_function(class_list_t *class_list, dev_class_info_t *cli)
    12341392{
    12351393        unsigned long key = (unsigned long) cli->devmap_handle;
    12361394       
    12371395        fibril_rwlock_write_lock(&class_list->rwlock);
    1238         hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
     1396        hash_table_insert(&class_list->devmap_functions, &key, &cli->devmap_link);
    12391397        fibril_rwlock_write_unlock(&class_list->rwlock);
    12401398
    1241         assert(find_devmap_class_device(class_list, cli->devmap_handle) != NULL);
    1242 }
    1243 
    1244 void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
    1245 {
    1246         unsigned long key = (unsigned long) node->devmap_handle;
     1399        assert(find_devmap_class_function(class_list, cli->devmap_handle) != NULL);
     1400}
     1401
     1402void tree_add_devmap_function(dev_tree_t *tree, fun_node_t *fun)
     1403{
     1404        unsigned long key = (unsigned long) fun->devmap_handle;
    12471405        fibril_rwlock_write_lock(&tree->rwlock);
    1248         hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
     1406        hash_table_insert(&tree->devmap_functions, &key, &fun->devmap_fun);
    12491407        fibril_rwlock_write_unlock(&tree->rwlock);
    12501408}
  • uspace/srv/devman/devman.h

    r5716e9a r76b5a95c  
    5656#define DEVMAP_SEPARATOR '\\'
    5757
    58 struct node;
    59 typedef struct node node_t;
     58struct dev_node;
     59typedef struct dev_node dev_node_t;
     60
     61struct fun_node;
     62typedef struct fun_node fun_node_t;
    6063
    6164typedef enum {
     
    117120} device_state_t;
    118121
    119 /** Representation of a node in the device tree. */
    120 struct node {
     122/** Device node in the device tree. */
     123struct dev_node {
    121124        /** The global unique identifier of the device. */
    122125        devman_handle_t handle;
    123         /** The name of the device specified by its parent. */
    124         char *name;
    125        
    126         /**
    127          * Full path and name of the device in device hierarchi (i. e. in full
    128          * path in device tree).
    129          */
    130         char *pathname;
    131        
    132         /** The node of the parent device. */
    133         node_t *parent;
    134        
    135         /**
    136          * Pointers to previous and next child devices in the linked list of
    137          * parent device's node.
    138          */
    139         link_t sibling;
    140        
    141         /** List of child device nodes. */
    142         link_t children;
    143         /** List of device ids for device-to-driver matching. */
    144         match_id_list_t match_ids;
     126       
     127        /** (Parent) function the device is attached to. */
     128        fun_node_t *pfun;
     129       
     130        /** List of device functions. */
     131        link_t functions;
    145132        /** Driver of this device. */
    146133        driver_t *drv;
    147134        /** The state of the device. */
    148135        device_state_t state;
    149         /**
    150          * Pointer to the previous and next device in the list of devices
    151          * owned by one driver.
    152          */
     136        /** Link to list of devices owned by driver (driver_t.devices) */
    153137        link_t driver_devices;
    154138       
    155         /** The list of device classes to which this device belongs. */
    156         link_t classes;
    157         /** Devmap handle if the device is registered by devmapper. */
    158         devmap_handle_t devmap_handle;
    159        
    160139        /**
    161140         * Used by the hash table of devices indexed by devman device handles.
    162141         */
    163         link_t devman_link;
    164        
    165         /**
    166          * Used by the hash table of devices indexed by devmap device handles.
    167          */
    168         link_t devmap_link;
    169 
     142        link_t devman_dev;
     143       
    170144        /**
    171145         * Whether this device was already passed to the driver.
     
    173147        bool passed_to_driver;
    174148};
     149
     150/** Function node in the device tree. */
     151struct fun_node {
     152        /** The global unique identifier of the function */
     153        devman_handle_t handle;
     154        /** Name of the function, assigned by the device driver */
     155        char *name;
     156       
     157        /** Full path and name of the device in device hierarchy */
     158        char *pathname;
     159       
     160        /** Device which this function belongs to */
     161        dev_node_t *dev;
     162       
     163        /** Link to list of functions in the device (ddf_dev_t.functions) */
     164        link_t dev_functions;
     165       
     166        /** Child device node (if any attached). */
     167        dev_node_t *child;
     168        /** List of device ids for device-to-driver matching. */
     169        match_id_list_t match_ids;
     170       
     171        /** The list of device classes to which this device function belongs. */
     172        link_t classes;
     173        /** Devmap handle if the device function is registered by devmap. */
     174        devmap_handle_t devmap_handle;
     175       
     176        /**
     177         * Used by the hash table of functions indexed by devman device handles.
     178         */
     179        link_t devman_fun;
     180       
     181        /**
     182         * Used by the hash table of functions indexed by devmap device handles.
     183         */
     184        link_t devmap_fun;
     185};
     186
    175187
    176188/** Represents device tree. */
    177189typedef struct dev_tree {
    178190        /** Root device node. */
    179         node_t *root_node;
     191        fun_node_t *root_node;
    180192       
    181193        /**
     
    191203        hash_table_t devman_devices;
    192204       
     205        /** Hash table of all devices indexed by devman handles. */
     206        hash_table_t devman_functions;
     207       
    193208        /**
    194209         * Hash table of devices registered by devmapper, indexed by devmap
    195210         * handles.
    196211         */
    197         hash_table_t devmap_devices;
     212        hash_table_t devmap_functions;
    198213} dev_tree_t;
    199214
     
    227242
    228243/**
    229  * Provides n-to-m mapping between device nodes and classes - each device may
    230  * be register to the arbitrary number of classes and each class may contain
    231  * the arbitrary number of devices.
     244 * Provides n-to-m mapping between function nodes and classes - each function
     245 * can register in an arbitrary number of classes and each class can contain
     246 * an arbitrary number of device functions.
    232247 */
    233248typedef struct dev_class_info {
     
    235250        dev_class_t *dev_class;
    236251        /** The device. */
    237         node_t *dev;
     252        fun_node_t *fun;
    238253       
    239254        /**
     
    249264        link_t dev_classes;
    250265       
    251         /** The name of the device within the class. */
     266        /** The name of the device function within the class. */
    252267        char *dev_name;
    253268        /** The handle of the device by device mapper in the class namespace. */
     
    270285         * indexed by devmap handles.
    271286         */
    272         hash_table_t devmap_devices;
     287        hash_table_t devmap_functions;
    273288       
    274289        /** Fibril mutex for list of classes. */
     
    278293/* Match ids and scores */
    279294
    280 extern int get_match_score(driver_t *, node_t *);
     295extern int get_match_score(driver_t *, dev_node_t *);
    281296
    282297extern bool parse_match_ids(char *, match_id_list_t *);
     
    292307extern int lookup_available_drivers(driver_list_t *, const char *);
    293308
    294 extern driver_t *find_best_match_driver(driver_list_t *, node_t *);
    295 extern bool assign_driver(node_t *, driver_list_t *, dev_tree_t *);
     309extern driver_t *find_best_match_driver(driver_list_t *, dev_node_t *);
     310extern bool assign_driver(dev_node_t *, driver_list_t *, dev_tree_t *);
    296311
    297312extern void add_driver(driver_list_t *, driver_t *);
    298 extern void attach_driver(node_t *, driver_t *);
    299 extern void add_device(int, driver_t *, node_t *, dev_tree_t *);
     313extern void attach_driver(dev_node_t *, driver_t *);
     314extern void add_device(int, driver_t *, dev_node_t *, dev_tree_t *);
    300315extern bool start_driver(driver_t *);
    301316
     
    310325/* Device nodes */
    311326
    312 extern node_t *create_dev_node(void);
    313 extern void delete_dev_node(node_t *node);
    314 extern node_t *find_dev_node_no_lock(dev_tree_t *tree,
     327extern dev_node_t *create_dev_node(void);
     328extern void delete_dev_node(dev_node_t *node);
     329extern dev_node_t *find_dev_node_no_lock(dev_tree_t *tree,
    315330    devman_handle_t handle);
    316 extern node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle);
    317 extern node_t *find_dev_node_by_path(dev_tree_t *, char *);
    318 extern node_t *find_node_child(node_t *, const char *);
     331extern dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle);
     332extern dev_node_t *find_dev_function(dev_node_t *, const char *);
     333
     334extern fun_node_t *create_fun_node(void);
     335extern void delete_fun_node(fun_node_t *);
     336extern fun_node_t *find_fun_node_no_lock(dev_tree_t *tree,
     337    devman_handle_t handle);
     338extern fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle);
     339extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
    319340
    320341/* Device tree */
    321342
    322343extern bool init_device_tree(dev_tree_t *, driver_list_t *);
    323 extern bool create_root_node(dev_tree_t *);
    324 extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *);
     344extern bool create_root_nodes(dev_tree_t *);
     345extern bool insert_dev_node(dev_tree_t *, dev_node_t *, fun_node_t *);
     346extern bool insert_fun_node(dev_tree_t *, fun_node_t *, char *, dev_node_t *);
    325347
    326348/* Device classes */
     
    330352extern size_t get_new_class_dev_idx(dev_class_t *);
    331353extern char *create_dev_name_for_class(dev_class_t *, const char *);
    332 extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *,
     354extern dev_class_info_t *add_function_to_class(fun_node_t *, dev_class_t *,
    333355    const char *);
    334356
     
    341363/* Devmap devices */
    342364
    343 extern node_t *find_devmap_tree_device(dev_tree_t *, devmap_handle_t);
    344 extern node_t *find_devmap_class_device(class_list_t *, devmap_handle_t);
    345 
    346 extern void class_add_devmap_device(class_list_t *, dev_class_info_t *);
    347 extern void tree_add_devmap_device(dev_tree_t *, node_t *);
     365extern void devmap_register_tree_function(fun_node_t *, dev_tree_t *);
     366
     367extern fun_node_t *find_devmap_tree_function(dev_tree_t *, devmap_handle_t);
     368extern fun_node_t *find_devmap_class_function(class_list_t *, devmap_handle_t);
     369
     370extern void class_add_devmap_function(class_list_t *, dev_class_info_t *);
     371extern void tree_add_devmap_function(dev_tree_t *, fun_node_t *);
    348372
    349373#endif
  • uspace/srv/devman/main.c

    r5716e9a r76b5a95c  
    199199static int assign_driver_fibril(void *arg)
    200200{
    201         node_t *node = (node_t *) arg;
    202         assign_driver(node, &drivers_list, &device_tree);
     201        dev_node_t *dev_node = (dev_node_t *) arg;
     202        assign_driver(dev_node, &drivers_list, &device_tree);
    203203        return EOK;
    204204}
    205205
    206 /** Handle child device registration.
     206/** Handle function registration.
    207207 *
    208208 * Child devices are registered by their parent's device driver.
    209209 */
    210 static void devman_add_child(ipc_callid_t callid, ipc_call_t *call)
    211 {
    212         devman_handle_t parent_handle = IPC_GET_ARG1(*call);
    213         sysarg_t match_count = IPC_GET_ARG2(*call);
     210static void devman_add_function(ipc_callid_t callid, ipc_call_t *call)
     211{
     212        fun_type_t ftype = (fun_type_t) IPC_GET_ARG1(*call);
     213        devman_handle_t dev_handle = IPC_GET_ARG2(*call);
     214        sysarg_t match_count = IPC_GET_ARG3(*call);
    214215        dev_tree_t *tree = &device_tree;
    215216       
    216217        fibril_rwlock_write_lock(&tree->rwlock);
    217         node_t *parent = find_dev_node_no_lock(&device_tree, parent_handle);
    218        
    219         if (parent == NULL) {
     218
     219        dev_node_t *dev = NULL;
     220        dev_node_t *pdev = find_dev_node_no_lock(&device_tree, dev_handle);
     221       
     222        if (pdev == NULL) {
    220223                fibril_rwlock_write_unlock(&tree->rwlock);
    221224                async_answer_0(callid, ENOENT);
     
    223226        }
    224227       
    225         char *dev_name = NULL;
    226         int rc = async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0);
     228        if (ftype != fun_inner && ftype != fun_exposed) {
     229                /* Unknown function type */
     230                printf(NAME ": Error, unknown function type provided by driver!\n");
     231
     232                fibril_rwlock_write_unlock(&tree->rwlock);
     233                async_answer_0(callid, EINVAL);
     234                return;
     235        }
     236       
     237        char *fun_name = NULL;
     238        int rc = async_data_write_accept((void **)&fun_name, true, 0, 0, 0, 0);
    227239        if (rc != EOK) {
    228240                fibril_rwlock_write_unlock(&tree->rwlock);
     
    231243        }
    232244       
    233         node_t *node = create_dev_node();
    234         if (!insert_dev_node(&device_tree, node, dev_name, parent)) {
     245        fun_node_t *fun = create_fun_node();
     246        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
    235247                fibril_rwlock_write_unlock(&tree->rwlock);
    236                 delete_dev_node(node);
     248                delete_fun_node(fun);
    237249                async_answer_0(callid, ENOMEM);
    238250                return;
    239251        }
    240252
     253        if (ftype == fun_inner) {
     254                dev = create_dev_node();
     255                if (dev == NULL) {
     256                        fibril_rwlock_write_unlock(&tree->rwlock);
     257                        delete_fun_node(fun);
     258                        async_answer_0(callid, ENOMEM);
     259                        return;
     260                }
     261
     262                insert_dev_node(tree, dev, fun);
     263        }
     264
    241265        fibril_rwlock_write_unlock(&tree->rwlock);
    242266       
    243         printf(NAME ": devman_add_child %s\n", node->pathname);
    244        
    245         devman_receive_match_ids(match_count, &node->match_ids);
    246 
    247         /*
    248          * Try to find a suitable driver and assign it to the device.  We do
    249          * not want to block the current fibril that is used for processing
    250          * incoming calls: we will launch a separate fibril to handle the
    251          * driver assigning. That is because assign_driver can actually include
    252          * task spawning which could take some time.
    253          */
    254         fid_t assign_fibril = fibril_create(assign_driver_fibril, node);
    255         if (assign_fibril == 0) {
     267        printf(NAME ": devman_add_function %s\n", fun->pathname);
     268       
     269        devman_receive_match_ids(match_count, &fun->match_ids);
     270
     271        if (ftype == fun_inner) {
     272                assert(dev != NULL);
    256273                /*
    257                  * Fallback in case we are out of memory.
    258                  * Probably not needed as we will die soon anyway ;-).
     274                 * Try to find a suitable driver and assign it to the device.  We do
     275                 * not want to block the current fibril that is used for processing
     276                 * incoming calls: we will launch a separate fibril to handle the
     277                 * driver assigning. That is because assign_driver can actually include
     278                 * task spawning which could take some time.
    259279                 */
    260                 (void) assign_driver_fibril(node);
     280                fid_t assign_fibril = fibril_create(assign_driver_fibril, dev);
     281                if (assign_fibril == 0) {
     282                        /*
     283                         * Fallback in case we are out of memory.
     284                         * Probably not needed as we will die soon anyway ;-).
     285                         */
     286                        (void) assign_driver_fibril(fun);
     287                } else {
     288                        fibril_add_ready(assign_fibril);
     289                }
    261290        } else {
    262                 fibril_add_ready(assign_fibril);
    263         }
    264 
     291                devmap_register_tree_function(fun, tree);
     292        }
     293       
    265294        /* Return device handle to parent's driver. */
    266         async_answer_1(callid, EOK, node->handle);
     295        async_answer_1(callid, EOK, fun->handle);
    267296}
    268297
     
    288317         * mapper.
    289318         */
    290         class_add_devmap_device(&class_list, cli);
     319        class_add_devmap_function(&class_list, cli);
    291320       
    292321        free(devmap_pathname);
    293322}
    294323
    295 static void devman_add_device_to_class(ipc_callid_t callid, ipc_call_t *call)
     324static void devman_add_function_to_class(ipc_callid_t callid, ipc_call_t *call)
    296325{
    297326        devman_handle_t handle = IPC_GET_ARG1(*call);
     
    306335        }       
    307336       
    308         node_t *dev = find_dev_node(&device_tree, handle);
    309         if (dev == NULL) {
     337        fun_node_t *fun = find_fun_node(&device_tree, handle);
     338        if (fun == NULL) {
    310339                async_answer_0(callid, ENOENT);
    311340                return;
     
    313342       
    314343        dev_class_t *cl = get_dev_class(&class_list, class_name);
    315         dev_class_info_t *class_info = add_device_to_class(dev, cl, NULL);
     344        dev_class_info_t *class_info = add_function_to_class(fun, cl, NULL);
    316345       
    317346        /* Register the device's class alias by devmapper. */
    318347        devmap_register_class_dev(class_info);
    319348       
    320         printf(NAME ": device '%s' added to class '%s', class name '%s' was "
    321             "asigned to it\n", dev->pathname, class_name, class_info->dev_name);
     349        printf(NAME ": function'%s' added to class '%s', class name '%s' was "
     350            "asigned to it\n", fun->pathname, class_name, class_info->dev_name);
    322351
    323352        async_answer_0(callid, EOK);
     
    372401                        cont = false;
    373402                        continue;
    374                 case DEVMAN_ADD_CHILD_DEVICE:
    375                         devman_add_child(callid, &call);
     403                case DEVMAN_ADD_FUNCTION:
     404                        devman_add_function(callid, &call);
    376405                        break;
    377406                case DEVMAN_ADD_DEVICE_TO_CLASS:
    378                         devman_add_device_to_class(callid, &call);
     407                        devman_add_function_to_class(callid, &call);
    379408                        break;
    380409                default:
     
    387416/** Find handle for the device instance identified by the device's path in the
    388417 * device tree. */
    389 static void devman_device_get_handle(ipc_callid_t iid, ipc_call_t *icall)
     418static void devman_function_get_handle(ipc_callid_t iid, ipc_call_t *icall)
    390419{
    391420        char *pathname;
     
    397426        }
    398427       
    399         node_t * dev = find_dev_node_by_path(&device_tree, pathname);
     428        fun_node_t *fun = find_fun_node_by_path(&device_tree, pathname);
    400429       
    401430        free(pathname);
    402431
    403         if (dev == NULL) {
     432        if (fun == NULL) {
    404433                async_answer_0(iid, ENOENT);
    405434                return;
    406435        }
    407        
    408         async_answer_1(iid, EOK, dev->handle);
     436
     437        async_answer_1(iid, EOK, fun->handle);
    409438}
    410439
     
    426455                        continue;
    427456                case DEVMAN_DEVICE_GET_HANDLE:
    428                         devman_device_get_handle(callid, &call);
     457                        devman_function_get_handle(callid, &call);
    429458                        break;
    430459                default:
     
    438467{
    439468        devman_handle_t handle = IPC_GET_ARG2(*icall);
    440        
    441         node_t *dev = find_dev_node(&device_tree, handle);
    442         if (dev == NULL) {
    443                 printf(NAME ": devman_forward error - no device with handle %" PRIun
    444                     " was found.\n", handle);
     469        devman_handle_t fwd_h;
     470        fun_node_t *fun = NULL;
     471        dev_node_t *dev = NULL;
     472       
     473        fun = find_fun_node(&device_tree, handle);
     474        if (fun == NULL)
     475                dev = find_dev_node(&device_tree, handle);
     476        else
     477                dev = fun->dev;
     478
     479        if (fun == NULL && dev == NULL) {
     480                printf(NAME ": devman_forward error - no device or function with "
     481                    "handle %" PRIun " was found.\n", handle);
    445482                async_answer_0(iid, ENOENT);
    446483                return;
    447484        }
     485
     486        if (fun == NULL && !drv_to_parent) {
     487                printf(NAME ": devman_forward error - cannot connect to "
     488                    "handle %" PRIun ", refers to a device.\n", handle);
     489                async_answer_0(iid, ENOENT);
     490                return;
     491        }
    448492       
    449493        driver_t *driver = NULL;
    450494       
    451495        if (drv_to_parent) {
    452                 if (dev->parent != NULL)
    453                         driver = dev->parent->drv;
     496                /* Connect to parent function of a device (or device function). */
     497                if (dev->pfun->dev != NULL)
     498                        driver = dev->pfun->dev->drv;
     499                fwd_h = dev->pfun->handle;
    454500        } else if (dev->state == DEVICE_USABLE) {
     501                /* Connect to the specified function */
    455502                driver = dev->drv;
    456503                assert(driver != NULL);
     504
     505                fwd_h = handle;
    457506        }
    458507       
     
    478527        }
    479528
    480         printf(NAME ": devman_forward: forward connection to device %s to "
    481             "driver %s.\n", dev->pathname, driver->name);
    482         async_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);
     529        if (fun != NULL) {
     530                printf(NAME ": devman_forward: forward connection to function %s to "
     531                    "driver %s.\n", fun->pathname, driver->name);
     532        } else {
     533                printf(NAME ": devman_forward: forward connection to device %s to "
     534                    "driver %s.\n", dev->pfun->pathname, driver->name);
     535        }
     536
     537        async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE);
    483538}
    484539
     
    488543{
    489544        devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall);
    490         node_t *dev;
    491 
    492         dev = find_devmap_tree_device(&device_tree, devmap_handle);
    493         if (dev == NULL)
    494                 dev = find_devmap_class_device(&class_list, devmap_handle);
    495        
    496         if (dev == NULL || dev->drv == NULL) {
     545        fun_node_t *fun;
     546        dev_node_t *dev;
     547
     548        fun = find_devmap_tree_function(&device_tree, devmap_handle);
     549        if (fun == NULL)
     550                fun = find_devmap_class_function(&class_list, devmap_handle);
     551       
     552        if (fun == NULL || fun->dev->drv == NULL) {
    497553                async_answer_0(iid, ENOENT);
    498554                return;
    499555        }
     556       
     557        dev = fun->dev;
    500558       
    501559        if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
     
    504562        }
    505563       
    506         async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0,
     564        async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0,
    507565            IPC_FF_NONE);
    508566        printf(NAME ": devman_connection_devmapper: forwarded connection to "
    509             "device %s to driver %s.\n", dev->pathname, dev->drv->name);
     567            "device %s to driver %s.\n", fun->pathname, dev->drv->name);
    510568}
    511569
  • uspace/srv/devman/match.c

    r5716e9a r76b5a95c  
    5757}
    5858
    59 int get_match_score(driver_t *drv, node_t *dev)
     59int get_match_score(driver_t *drv, dev_node_t *dev)
    6060{
    6161        link_t *drv_head = &drv->match_ids.ids;
    62         link_t *dev_head = &dev->match_ids.ids;
     62        link_t *dev_head = &dev->pfun->match_ids.ids;
    6363       
    6464        if (list_empty(drv_head) || list_empty(dev_head))
  • uspace/srv/devmap/devmap.c

    r5716e9a r76b5a95c  
    123123static devmap_handle_t last_handle = 0;
    124124static devmap_device_t *null_devices[NULL_DEVICES];
     125
     126/*
     127 * Dummy list for null devices. This is necessary so that null devices can
     128 * be used just as any other devices, e.g. in devmap_device_unregister_core().
     129 */
     130static LIST_INITIALIZE(dummy_null_driver_devices);
    125131
    126132static devmap_handle_t devmap_create_handle(void)
     
    953959        device->name = dev_name;
    954960       
    955         /* Insert device into list of all devices
    956            and into null devices array */
     961        /*
     962         * Insert device into list of all devices and into null devices array.
     963         * Insert device into a dummy list of null driver's devices so that it
     964         * can be safely removed later.
     965         */
    957966        list_append(&device->devices, &devices_list);
     967        list_append(&device->driver_devices, &dummy_null_driver_devices);
    958968        null_devices[i] = device;
    959969       
  • uspace/srv/hid/console/gcons.c

    r5716e9a r76b5a95c  
    285285        ssize_t nx = (ssize_t) mouse_x + dx;
    286286        ssize_t ny = (ssize_t) mouse_y + dy;
    287 
    288         if (!use_gcons)
     287       
     288        /* Until gcons is initalized we don't have the screen resolution */
     289        if (xres == 0 || yres == 0)
    289290                return;
    290291       
  • uspace/srv/hid/kbd/Makefile

    r5716e9a r76b5a95c  
    7878                SOURCES += \
    7979                        port/pl050.c \
    80                         ctl/pl050.c
     80                        ctl/pc.c
    8181        endif
    8282endif
  • uspace/srv/loader/arch/abs32le/_link.ld.in

    r5716e9a r76b5a95c  
    33 * is the base address and the special interp section.
    44 */
     5
    56STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
    67ENTRY(__entry)
     
    5455        } :data
    5556       
    56         . = ALIGN(0x1000);
    57        
    58         _heap = .;
    59        
    6057        /DISCARD/ : {
    6158                *(*);
  • uspace/srv/loader/arch/amd64/_link.ld.in

    r5716e9a r76b5a95c  
     1/*
     2 * The difference from _link.ld.in for regular statically-linked apps
     3 * is the base address and the special interp section.
     4 */
     5
    16STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
    27ENTRY(__entry)
     
    611        text PT_LOAD FLAGS(5);
    712        data PT_LOAD FLAGS(6);
     13        debug PT_NOTE;
    814}
    915
     
    1117        .interp : {
    1218                *(.interp);
    13         } : interp
    14 
    15         /* . = 0x0000700000001000;*/
     19        } :interp
     20       
     21        /* . = 0x0000700000001000; */
    1622        . = 0x70001000;
    1723       
     
    1925                *(.init);
    2026        } :text
     27       
    2128        .text : {
    2229                *(.text);
     
    2734                *(.data);
    2835        } :data
     36       
    2937        .tdata : {
    3038                _tdata_start = .;
     
    3240                _tdata_end = .;
    3341        } :data
     42       
    3443        .tbss : {
    3544                _tbss_start = .;
     
    3746                _tbss_end = .;
    3847        } :data
     48       
    3949        _tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
     50       
    4051        .bss : {
    4152                *(COMMON);
    4253                *(.bss);
    4354        } :data
    44 
    45         . = ALIGN(0x1000);
    46         _heap = .;
     55       
     56#ifdef CONFIG_LINE_DEBUG
     57        .comment 0 : { *(.comment); } :debug
     58        .debug_abbrev 0 : { *(.debug_abbrev); } :debug
     59        .debug_aranges 0 : { *(.debug_aranges); } :debug
     60        .debug_info 0 : { *(.debug_info); } :debug
     61        .debug_line 0 : { *(.debug_line); } :debug
     62        .debug_loc 0 : { *(.debug_loc); } :debug
     63        .debug_pubnames 0 : { *(.debug_pubnames); } :debug
     64        .debug_pubtypes 0 : { *(.debug_pubtypes); } :debug
     65        .debug_ranges 0 : { *(.debug_ranges); } :debug
     66        .debug_str 0 : { *(.debug_str); } :debug
     67#endif
    4768       
    4869        /DISCARD/ : {
    4970                *(*);
    5071        }
    51 
    5272}
  • uspace/srv/loader/arch/arm32/_link.ld.in

    r5716e9a r76b5a95c  
    33 * is the base address.
    44 */
     5
    56STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
    67ENTRY(__entry)
     
    1617                *(.interp);
    1718        } : interp
    18 
     19       
    1920        . = 0x70001000;
    20 
     21       
    2122        .init ALIGN(0x1000): SUBALIGN(0x1000) {
    2223                *(.init);
    23         } : text
     24        } :text
     25       
    2426        .text : {
    2527                *(.text);
    26         *(.rodata*);
     28                *(.rodata*);
    2729        } :text
    2830       
     
    3234                *(.sdata);
    3335        } :data
     36       
    3437        .tdata : {
    3538                _tdata_start = .;
     
    3740                _tdata_end = .;
    3841        } :data
     42       
    3943        .tbss : {
    4044                _tbss_start = .;
     
    4246                _tbss_end = .;
    4347        } :data
     48       
    4449        _tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
     50       
    4551        .bss : {
    4652                *(.sbss);
    4753                *(.scommon);
    48         *(COMMON);
    49         *(.bss);
     54                *(COMMON);
     55                *(.bss);
    5056        } :data
    51        
    52         . = ALIGN(0x1000);
    53         _heap = .;
    5457       
    5558        /DISCARD/ : {
    5659                *(*);
    5760        }
    58 
    5961}
  • uspace/srv/loader/arch/ia32/_link.ld.in

    r5716e9a r76b5a95c  
    33 * is the base address and the special interp section.
    44 */
     5
    56STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
    67ENTRY(__entry)
     
    1011        text PT_LOAD FILEHDR PHDRS FLAGS(5);
    1112        data PT_LOAD FLAGS(6);
     13        debug PT_NOTE;
    1214}
    1315
     
    5254        } :data
    5355       
    54         . = ALIGN(0x1000);
    55        
    56         _heap = .;
     56#ifdef CONFIG_LINE_DEBUG
     57        .comment 0 : { *(.comment); } :debug
     58        .debug_abbrev 0 : { *(.debug_abbrev); } :debug
     59        .debug_aranges 0 : { *(.debug_aranges); } :debug
     60        .debug_info 0 : { *(.debug_info); } :debug
     61        .debug_line 0 : { *(.debug_line); } :debug
     62        .debug_loc 0 : { *(.debug_loc); } :debug
     63        .debug_pubnames 0 : { *(.debug_pubnames); } :debug
     64        .debug_pubtypes 0 : { *(.debug_pubtypes); } :debug
     65        .debug_ranges 0 : { *(.debug_ranges); } :debug
     66        .debug_str 0 : { *(.debug_str); } :debug
     67#endif
    5768       
    5869        /DISCARD/ : {
  • uspace/srv/loader/arch/ia64/_link.ld.in

    r5716e9a r76b5a95c  
    1212                *(.interp);
    1313        } :interp
    14 
     14       
    1515        /* On Itanium code sections must be aligned to 16 bytes. */
    1616        . = ALIGN(0x800000000 + SIZEOF_HEADERS, 16);
    17 
     17       
    1818        .init : {
    1919                *(.init);
    20         } : text
     20        } :text
     21       
    2122        .text : {
    2223                *(.text);
    2324                *(.rodata*);
    2425        } :text
    25 
     26       
    2627        . = . + 0x4000;
    27 
     28       
    2829        .got : {
    2930                _gp = .;
    3031                *(.got*);
    31         } :data
     32        } :data
     33       
    3234        .data : {
    3335                *(.opd);
     
    3537                *(.sdata);
    3638        } :data
     39       
    3740        .tdata : {
    3841                _tdata_start = .;
     
    4043                _tdata_end = .;
    4144        } :data
     45       
    4246        .tbss : {
    4347                _tbss_start = .;
     
    4549                _tbss_end = .;
    4650        } :data
     51       
    4752        _tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
     53       
    4854        .bss : {
    4955                *(.sbss);
     
    5258                *(.bss);
    5359        } :data
    54 
    55         . = ALIGN(0x4000);
    56         _heap = .;
    57  
     60       
    5861        /DISCARD/ : {
    5962                *(*);
    60         }
     63        }
    6164}
  • uspace/srv/loader/arch/mips32/_link.ld.in

    r5716e9a r76b5a95c  
    33 * is the base address.
    44 */
     5
    56STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
    67ENTRY(__entry)
     
    1617                *(.interp);
    1718        } :interp
    18 
     19       
    1920        . = 0x70004000;
    2021       
     
    2223                *(.init);
    2324        } :text
     25       
    2426        .text : {
    25                 *(.text);
     27                *(.text);
    2628                *(.rodata*);
    2729        } :text
    28 
     30       
     31        . = . + 0x4000;
     32       
    2933        .data : {
    3034                *(.data);
    3135                *(.data.rel*);
    3236        } :data
    33 
     37       
    3438        .got : {
    3539                _gp = .;
    3640                *(.got);
    3741        } :data
    38 
     42       
    3943        .tdata : {
    4044                _tdata_start = .;
     
    4246                _tdata_end = .;
    4347        } :data
     48       
    4449        .tbss : {
    4550                _tbss_start = .;
     
    4752                _tbss_end = .;
    4853        } :data
     54       
    4955        _tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
    50 
     56       
    5157        .sbss : {
    5258                *(.scommon);
    5359                *(.sbss);
    54         }       
     60        }
     61       
    5562        .bss : {
    5663                *(.bss);
    5764                *(COMMON);
    5865        } :data
    59 
    60         . = ALIGN(0x4000);
    61         _heap = .;
    62 
     66       
    6367        /DISCARD/ : {
    6468                *(*);
  • uspace/srv/loader/arch/ppc32/_link.ld.in

    r5716e9a r76b5a95c  
    33 * is the base address.
    44 */
     5
    56STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
    67ENTRY(__entry)
     
    1617                *(.interp);
    1718        } :interp
    18 
     19       
    1920        . = 0x70001000;
    20 
     21       
    2122        .init ALIGN(0x1000) : SUBALIGN(0x1000) {
    2223                *(.init);
    2324        } :text
     25       
    2426        .text : {
    2527                *(.text);
     
    3133                *(.sdata);
    3234        } :data
     35       
    3336        .tdata : {
    3437                _tdata_start = .;
     
    3639                _tdata_end = .;
    3740        } :data
     41       
    3842        .tbss : {
    3943                _tbss_start = .;
     
    4145                _tbss_end = .;
    4246        } :data
     47       
    4348        _tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
     49       
    4450        .bss : {
    4551                *(.sbss);
     
    4753                *(.bss);
    4854        } :data
    49 
    50         . = ALIGN(0x1000);
    51         _heap = .;
    5255       
    5356        /DISCARD/ : {
    5457                *(*);
    5558        }
    56 
    5759}
  • uspace/srv/loader/arch/sparc64/_link.ld.in

    r5716e9a r76b5a95c  
    1212                *(.interp);
    1313        } :interp
    14 
     14       
    1515        . = 0x70004000 + SIZEOF_HEADERS;
    16 
     16       
    1717        .init : {
    1818                *(.init);
    1919        } :text
     20       
    2021        .text : {
    2122                *(.text);
    2223                *(.rodata*);
    2324        } :text
    24 
     25       
    2526        . = . + 0x4000;
    26 
     27       
    2728        .got : {
    2829                 _gp = .;
    2930                 *(.got*);
    3031        } :data
     32       
    3133        .data : {
    3234                *(.data);
    3335                *(.sdata);
    3436        } :data
     37       
    3538        .tdata : {
    3639                _tdata_start = .;
     
    3841                _tdata_end = .;
    3942        } :data
     43       
    4044        .tbss : {
    4145                _tbss_start = .;
     
    4347                _tbss_end = .;
    4448        } :data
     49       
    4550        _tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
     51       
    4652        .bss : {
    4753                *(.sbss);
     
    4955                *(.bss);
    5056        } :data
    51 
    52         . = ALIGN(0x4000);
    53         _heap = .;
    5457       
    5558        /DISCARD/ : {
    5659                *(*);
    5760        }
    58 
    5961}
  • uspace/srv/loader/elf_load.c

    r5716e9a r76b5a95c  
    109109        int fd;
    110110        int rc;
    111 
     111       
    112112        fd = open(file_name, O_RDONLY);
    113113        if (fd < 0) {
     
    300300        case PT_NULL:
    301301        case PT_PHDR:
     302        case PT_NOTE:
    302303                break;
    303304        case PT_LOAD:
     
    310311        case PT_DYNAMIC:
    311312        case PT_SHLIB:
    312         case PT_NOTE:
    313313        case PT_LOPROC:
    314314        case PT_HIPROC:
     
    344344        seg_ptr = (void *) seg_addr;
    345345
    346         DPRINTF("Load segment at addr %p, size 0x%x\n", seg_addr,
     346        DPRINTF("Load segment at addr %p, size 0x%x\n", (void *) seg_addr,
    347347                entry->p_memsz);
    348348
     
    372372        mem_sz = entry->p_memsz + (entry->p_vaddr - base);
    373373
    374         DPRINTF("Map to seg_addr=%p-%p.\n", seg_addr,
    375         entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE));
     374        DPRINTF("Map to seg_addr=%p-%p.\n", (void *) seg_addr,
     375            (void *) (entry->p_vaddr + bias +
     376            ALIGN_UP(entry->p_memsz, PAGE_SIZE)));
    376377
    377378        /*
     
    386387        }
    387388
    388         DPRINTF("as_area_create(%p, 0x%x, %d) -> 0x%lx\n",
    389                 base + bias, mem_sz, flags, (uintptr_t)a);
     389        DPRINTF("as_area_create(%p, %#zx, %d) -> %p\n",
     390            (void *) (base + bias), mem_sz, flags, (void *) a);
    390391
    391392        /*
     
    464465                    (void *)((uint8_t *)entry->sh_addr + elf->bias);
    465466                DPRINTF("Dynamic section found at %p.\n",
    466                         (uintptr_t)elf->info->dynamic);
     467                    (void *) elf->info->dynamic);
    467468                break;
    468469        default:
  • uspace/srv/net/tl/udp/udp.c

    r5716e9a r76b5a95c  
    740740        int socket_id;
    741741        size_t addrlen;
    742         size_t size;
     742        size_t size = 0;
    743743        ipc_call_t answer;
    744744        size_t answer_count;
Note: See TracChangeset for help on using the changeset viewer.