Changeset d6b1359 in mainline for uspace/lib


Ignore:
Timestamp:
2011-01-09T18:00:14Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
80bffdb0
Parents:
0c70f7e (diff), 8871dba (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 mildly aggressive DDF cleanup (char_dev and hw_res interfaces, ops structures).

Location:
uspace/lib
Files:
7 edited
8 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    r0c70f7e rd6b1359  
    5959        generic/devman.c \
    6060        generic/device/hw_res.c \
    61         generic/device/char.c \
     61        generic/device/char_dev.c \
    6262        generic/event.c \
    6363        generic/errno.c \
  • uspace/lib/c/generic/device/char_dev.c

    r0c70f7e rd6b1359  
    3434
    3535#include <ipc/dev_iface.h>
    36 #include <device/char.h>
     36#include <device/char_dev.h>
    3737#include <errno.h>
    3838#include <async.h>
     
    4545 * using its character interface.
    4646 *
    47  * @param dev_phone Phone to the device.
    48  * @param buf       Buffer for the data read
    49  *                  from or written to the device.
    50  * @param len       Maximum length of the data to be
    51  *                  read or written.
    52  * @param read      Read from the device if true,
    53  *                  write to it otherwise.
     47 * @param dev_phone     Phone to the device.
     48 * @param buf           Buffer for the data read from or written to the device.
     49 * @param size          Maximum size of data (in bytes) to be read or written.
     50 * @param read          Read from the device if true, write to it otherwise.
    5451 *
    55  * @return Non-negative number of bytes actually read
    56  *         from or written to the device on success,
    57  *         negative error number otherwise.
    58  *
     52 * @return              Non-negative number of bytes actually read from or
     53 *                      written to the device on success, negative error number
     54 *                      otherwise.
    5955 */
    60 static ssize_t rw_dev(int dev_phone, void *buf, size_t len, bool read)
     56static ssize_t char_dev_rw(int dev_phone, void *buf, size_t size, bool read)
    6157{
    6258        async_serialize_start();
     
    6864        if (read) {
    6965                req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE),
    70                     CHAR_READ_DEV, &answer);
    71                 ret = async_data_read_start(dev_phone, buf, len);
     66                    CHAR_DEV_READ, &answer);
     67                ret = async_data_read_start(dev_phone, buf, size);
    7268        } else {
    7369                req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE),
    74                     CHAR_WRITE_DEV, &answer);
    75                 ret = async_data_write_start(dev_phone, buf, len);
     70                    CHAR_DEV_WRITE, &answer);
     71                ret = async_data_write_start(dev_phone, buf, size);
    7672        }
    7773       
     
    8278                if (rc == EOK)
    8379                        return (ssize_t) ret;
    84                        
     80               
    8581                return (ssize_t) rc;
    8682        }
     
    9692}
    9793
    98 /** Read from device using its character interface.
     94/** Read from character device.
    9995 *
    100  * @param dev_phone Phone to the device.
    101  * @param buf       Output buffer for the data
    102  *                  read from the device.
    103  * @param len       Maximum length of the data to be read.
     96 * @param dev_phone     Phone to the device.
     97 * @param buf           Output buffer for the data read from the device.
     98 * @param size          Maximum size (in bytes) of the data to be read.
    10499 *
    105  * @return Non-negative number of bytes actually read
    106  *         from the device on success, negative error
    107  *         number otherwise.
    108  *
     100 * @return              Non-negative number of bytes actually read from the
     101 *                      device on success, negative error number otherwise.
    109102 */
    110 ssize_t read_dev(int dev_phone, void *buf, size_t len)
     103ssize_t char_dev_read(int dev_phone, void *buf, size_t size)
    111104{
    112         return rw_dev(dev_phone, buf, len, true);
     105        return char_dev_rw(dev_phone, buf, size, true);
    113106}
    114107
    115 /** Write to device using its character interface.
     108/** Write to character device.
    116109 *
    117  * @param dev_phone Phone to the device.
    118  * @param buf       Input buffer containg the data
    119  *                  to be written to the device.
    120  * @param len       Maximum length of the data to be written.
     110 * @param dev_phone     Phone to the device.
     111 * @param buf           Input buffer containg the data to be written to the
     112 *                      device.
     113 * @param size          Maximum size (in bytes) of the data to be written.
    121114 *
    122  * @return Non-negative number of bytes actually written
    123  *         to the device on success, negative error number
    124  *         otherwise.
    125  *
     115 * @return              Non-negative number of bytes actually written to the
     116 *                      device on success, negative error number otherwise.
    126117 */
    127 ssize_t write_dev(int dev_phone, void *buf, size_t len)
     118ssize_t char_dev_write(int dev_phone, void *buf, size_t size)
    128119{
    129         return rw_dev(dev_phone, buf, len, false);
     120        return char_dev_rw(dev_phone, buf, size, false);
    130121}
    131122
  • uspace/lib/c/generic/device/hw_res.c

    r0c70f7e rd6b1359  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28  
     28
    2929 /** @addtogroup libc
    3030 * @{
     
    3232/** @file
    3333 */
    34  
     34
    3535#include <device/hw_res.h>
    3636#include <errno.h>
     
    3838#include <malloc.h>
    3939
    40 int get_hw_resources(int dev_phone, hw_resource_list_t *hw_resources)
     40int hw_res_get_resource_list(int dev_phone, hw_resource_list_t *hw_resources)
    4141{
    4242        sysarg_t count = 0;
    43         int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), GET_RESOURCE_LIST, &count);
     43
     44        int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE),
     45            HW_RES_GET_RESOURCE_LIST, &count);
     46
    4447        hw_resources->count = count;
    4548        if (rc != EOK)
     
    5760                return rc;
    5861        }
    59                  
     62       
    6063        return EOK;
    6164}
    6265
    63 bool enable_interrupt(int dev_phone)
     66bool hw_res_enable_interrupt(int dev_phone)
    6467{
    65         int rc = async_req_1_0(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), ENABLE_INTERRUPT);
     68        int rc = async_req_1_0(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE),
     69            HW_RES_ENABLE_INTERRUPT);
     70
    6671        return rc == EOK;
    6772}
    68  
    69  
    70  
    71  /** @}
     73
     74/** @}
    7275 */
  • uspace/lib/c/include/device/char_dev.h

    r0c70f7e rd6b1359  
    2727 */
    2828
    29  /** @addtogroup libc
     29/** @addtogroup libc
    3030 * @{
    3131 */
     
    3333 */
    3434
    35 #ifndef LIBC_DEVICE_HW_RES_H_
    36 #define LIBC_DEVICE_HW_RES_H_
     35#ifndef LIBC_DEVICE_CHAR_DEV_H_
     36#define LIBC_DEVICE_CHAR_DEV_H_
    3737
    3838typedef enum {
    39         CHAR_READ_DEV = 0,
    40         CHAR_WRITE_DEV
    41 } hw_res_funcs_t;
     39        CHAR_DEV_READ = 0,
     40        CHAR_DEV_WRITE
     41} char_dev_method_t;
    4242
    43 ssize_t read_dev(int dev_phone, void *buf, size_t len);
    44 ssize_t write_dev(int dev_phone, void *buf, size_t len);
     43ssize_t char_dev_read(int dev_phone, void *buf, size_t len);
     44ssize_t char_dev_write(int dev_phone, void *buf, size_t len);
    4545
    4646#endif
  • uspace/lib/c/include/device/hw_res.h

    r0c70f7e rd6b1359  
    2727 */
    2828 
    29  /** @addtogroup libc
     29/** @addtogroup libc
    3030 * @{
    3131 */
     
    3939#include <bool.h>
    4040
    41 // HW resource provider interface
     41/** HW resource provider interface */
     42typedef enum {
     43        HW_RES_GET_RESOURCE_LIST = 0,
     44        HW_RES_ENABLE_INTERRUPT
     45} hw_res_method_t;
    4246
    43 typedef enum {
    44         GET_RESOURCE_LIST = 0,
    45         ENABLE_INTERRUPT       
    46 } hw_res_funcs_t;
    47 
    48 /** HW resource types. */
     47/** HW resource types */
    4948typedef enum {
    5049        INTERRUPT,
     
    5857} endianness_t;
    5958
    60 
    61 /** HW resource (e.g. interrupt, memory register, i/o register etc.). */
    62 typedef struct hw_resource {
     59/** HW resource (e.g. interrupt, memory register, i/o register etc.) */
     60typedef struct {
    6361        hw_res_type_t type;
    6462        union {
    6563                struct {
    6664                        uint64_t address;
    67                         endianness_t endianness;                       
    68                         size_t size;                   
     65                        endianness_t endianness;
     66                        size_t size;
    6967                } mem_range;
     68
    7069                struct {
    7170                        uint64_t address;
    72                         endianness_t endianness;                       
    73                         size_t size;                   
     71                        endianness_t endianness;
     72                        size_t size;
    7473                } io_range;
     74
    7575                struct {
    76                         int irq;                       
    77                 } interrupt;           
    78         } res; 
     76                        int irq;
     77                } interrupt;
     78        } res;
    7979} hw_resource_t;
    8080
    81 typedef struct hw_resource_list {
     81typedef struct {
    8282        size_t count;
    83         hw_resource_t *resources;       
     83        hw_resource_t *resources;
    8484} hw_resource_list_t;
    8585
    86 static inline void clean_hw_resource_list(hw_resource_list_t *hw_res)
     86static inline void hw_res_clean_resource_list(hw_resource_list_t *hw_res)
    8787{
    88         if(NULL != hw_res->resources) {
     88        if (hw_res->resources != NULL) {
    8989                free(hw_res->resources);
     90
    9091                hw_res->resources = NULL;
    9192        }
    92         hw_res->count = 0;     
     93
     94        hw_res->count = 0;
    9395}
    9496
    95 
    96 
    97 extern int get_hw_resources(int, hw_resource_list_t *);
    98 extern bool enable_interrupt(int);
    99 
     97extern int hw_res_get_resource_list(int, hw_resource_list_t *);
     98extern bool hw_res_enable_interrupt(int);
    10099
    101100#endif
  • uspace/lib/c/include/ipc/dev_iface.h

    r0c70f7e rd6b1359  
    3535#include <libarch/types.h>
    3636
    37 typedef enum { 
    38         HW_RES_DEV_IFACE = 0,   
     37typedef enum {
     38        HW_RES_DEV_IFACE = 0,
    3939        CHAR_DEV_IFACE,
    40         // TODO add more interfaces
    4140        DEV_IFACE_MAX
    4241} dev_inferface_idx_t;
  • uspace/lib/drv/Makefile

    r0c70f7e rd6b1359  
    3535        generic/driver.c \
    3636        generic/dev_iface.c \
    37         generic/remote_res.c \
    38         generic/remote_char.c
     37        generic/remote_hw_res.c \
     38        generic/remote_char_dev.c
    3939
    4040include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/drv/generic/dev_iface.c

    r0c70f7e rd6b1359  
    3737
    3838#include "dev_iface.h"
    39 #include "remote_res.h"
    40 #include "remote_char.h"
     39#include "remote_hw_res.h"
     40#include "remote_char_dev.h"
    4141
    4242static iface_dipatch_table_t remote_ifaces = {
    4343        .ifaces = {
    44                 &remote_res_iface,
    45                 &remote_char_iface
     44                &remote_hw_res_iface,
     45                &remote_char_dev_iface
    4646        }
    4747};
    4848
    4949remote_iface_t* get_remote_iface(int idx)
    50 {       
     50{
    5151        assert(is_valid_iface_idx(idx));
    5252        return remote_ifaces.ifaces[idx];
  • uspace/lib/drv/generic/remote_char_dev.c

    r0c70f7e rd6b1359  
    3737#include <errno.h>
    3838
    39 #include "char.h"
     39#include "ops/char_dev.h"
    4040#include "driver.h"
    4141
     
    4646
    4747/** Remote character interface operations. */
    48 static remote_iface_func_ptr_t remote_char_iface_ops [] = {
     48static remote_iface_func_ptr_t remote_char_dev_iface_ops[] = {
    4949        &remote_char_read,
    5050        &remote_char_write
     
    5656 * character interface.
    5757 */
    58 remote_iface_t remote_char_iface = {
    59         .method_count = sizeof(remote_char_iface_ops) /
     58remote_iface_t remote_char_dev_iface = {
     59        .method_count = sizeof(remote_char_dev_iface_ops) /
    6060            sizeof(remote_iface_func_ptr_t),
    61         .methods = remote_char_iface_ops
     61        .methods = remote_char_dev_iface_ops
    6262};
    6363
     
    7474remote_char_read(device_t *dev, void *iface, ipc_callid_t callid,
    7575    ipc_call_t *call)
    76 {       
    77         char_iface_t *char_iface = (char_iface_t *) iface;
     76{
     77        char_dev_ops_t *char_iface = (char_dev_ops_t *) iface;
    7878        ipc_callid_t cid;
    7979       
     
    122122    ipc_call_t *call)
    123123{
    124         char_iface_t *char_iface = (char_iface_t *) iface;
     124        char_dev_ops_t *char_iface = (char_dev_ops_t *) iface;
    125125        ipc_callid_t cid;
    126126        size_t len;
     
    136136                ipc_answer_0(callid, ENOTSUP);
    137137                return;
    138         }       
     138        }
    139139       
    140140        if (len > MAX_CHAR_RW_COUNT)
  • uspace/lib/drv/generic/remote_hw_res.c

    r0c70f7e rd6b1359  
    3737#include <errno.h>
    3838
     39#include "ops/hw_res.h"
    3940#include "driver.h"
    40 #include "resource.h"
    4141
    42 static void remote_res_get_resources(device_t *, void *, ipc_callid_t,
     42static void remote_res_get_resource_list(device_t *, void *, ipc_callid_t,
    4343    ipc_call_t *);
    4444static void remote_res_enable_interrupt(device_t *, void *, ipc_callid_t,
    4545    ipc_call_t *);
    4646
    47 static remote_iface_func_ptr_t remote_res_iface_ops [] = {
    48         &remote_res_get_resources,
     47static remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
     48        &remote_res_get_resource_list,
    4949        &remote_res_enable_interrupt
    5050};
    5151
    52 remote_iface_t remote_res_iface = {
    53         .method_count = sizeof(remote_res_iface_ops) /
     52remote_iface_t remote_hw_res_iface = {
     53        .method_count = sizeof(remote_hw_res_iface_ops) /
    5454            sizeof(remote_iface_func_ptr_t),
    55         .methods = remote_res_iface_ops
     55        .methods = remote_hw_res_iface_ops
    5656};
    5757
     
    5959    ipc_callid_t callid, ipc_call_t *call)
    6060{
    61         resource_iface_t *ires = (resource_iface_t *) iface;
     61        hw_res_ops_t *ires = (hw_res_ops_t *) iface;
    6262       
    6363        if (NULL == ires->enable_interrupt)
     
    6969}
    7070
    71 static void remote_res_get_resources(device_t *dev, void *iface,
     71static void remote_res_get_resource_list(device_t *dev, void *iface,
    7272    ipc_callid_t callid, ipc_call_t *call)
    7373{
    74         resource_iface_t *ires = (resource_iface_t *) iface;
    75         if (NULL == ires->get_resources) {
     74        hw_res_ops_t *ires = (hw_res_ops_t *) iface;
     75        if (NULL == ires->get_resource_list) {
    7676                ipc_answer_0(callid, ENOTSUP);
    7777                return;
    7878        }
    7979       
    80         hw_resource_list_t *hw_resources = ires->get_resources(dev);
     80        hw_resource_list_t *hw_resources = ires->get_resource_list(dev);
    8181        if (NULL == hw_resources){
    8282                ipc_answer_0(callid, ENOENT);
  • uspace/lib/drv/include/driver.h

    r0c70f7e rd6b1359  
    4141#include <ipc/devman.h>
    4242#include <ipc/dev_iface.h>
    43 #include <device/hw_res.h>
    44 #include <device/char.h>
    4543#include <assert.h>
    4644#include <ddi.h>
  • uspace/lib/drv/include/ops/char_dev.h

    r0c70f7e rd6b1359  
    3333 */
    3434
    35 #ifndef LIBDRV_CHAR_H_
    36 #define LIBDRV_CHAR_H_
     35#ifndef LIBDRV_OPS_CHAR_DEV_H_
     36#define LIBDRV_OPS_CHAR_DEV_H_
    3737
    38 #include "driver.h"
     38#include "../driver.h"
    3939
    40 typedef struct char_iface {
     40typedef struct {
    4141        int (*read)(device_t *, char *, size_t);
    4242        int (*write)(device_t *, char *, size_t);
    43 } char_iface_t;
     43} char_dev_ops_t;
    4444
    4545#endif
  • uspace/lib/drv/include/ops/hw_res.h

    r0c70f7e rd6b1359  
    3333 */
    3434
    35 #ifndef LIBDRV_RESOURCE_H_
    36 #define LIBDRV_RESOURCE_H_
     35#ifndef LIBDRV_OPS_HW_RES_H_
     36#define LIBDRV_OPS_HW_RES_H_
    3737
    38 #include "driver.h"
     38#include <device/hw_res.h>
     39#include <sys/types.h>
    3940
    40 typedef struct resource_iface {
    41          hw_resource_list_t *(* get_resources)(device_t *);
     41#include "../driver.h"
     42
     43typedef struct {
     44         hw_resource_list_t *(*get_resource_list)(device_t *);
    4245         bool (*enable_interrupt)(device_t *);
    43 } resource_iface_t;
    44 
     46} hw_res_ops_t;
    4547
    4648#endif
  • uspace/lib/drv/include/remote_char_dev.h

    r0c70f7e rd6b1359  
    3333 */
    3434
    35 #ifndef LIBDRV_REMOTE_RES_H_
    36 #define LIBDRV_REMOTE_RES_H_
     35#ifndef LIBDRV_REMOTE_CHAR_DEV_H_
     36#define LIBDRV_REMOTE_CHAR_DEV_H_
    3737
    38 remote_iface_t remote_res_iface;
     38extern remote_iface_t remote_char_dev_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/remote_hw_res.h

    r0c70f7e rd6b1359  
    3333 */
    3434
    35 #ifndef LIBDRV_REMOTE_CHAR_H_
    36 #define LIBDRV_REMOTE_CHAR_H_
     35#ifndef LIBDRV_REMOTE_HW_RES_H_
     36#define LIBDRV_REMOTE_HW_RES_H_
    3737
    38 remote_iface_t remote_char_iface;
     38extern remote_iface_t remote_hw_res_iface;
    3939
    4040#endif
Note: See TracChangeset for help on using the changeset viewer.