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

Changeset 5cd136ab in mainline


Ignore:
Timestamp:
2010-04-02T13:37:58Z (12 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master
Children:
9a66bc2
Parents:
57937dd
Message:

device interfaces and driver cooperation - parts of code

Location:
uspace
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/Makefile

    r57937dd r5cd136ab  
    5454        generic/devmap.c \
    5555        generic/devman.c \
     56        generic/device/hw_res.c \
    5657        generic/event.c \
    5758        generic/errno.c \
  • uspace/lib/libc/generic/devman.c

    r57937dd r5cd136ab  
    2828 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2929 */
     30 
     31 /** @addtogroup libc
     32 * @{
     33 */
     34/** @file
     35 */
    3036
    3137#include <string.h>
     
    193199        }
    194200}
     201
     202int devman_device_connect(device_handle_t handle, unsigned int flags)
     203{
     204        int phone;
     205       
     206        if (flags & IPC_FLAG_BLOCKING) {
     207                phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,
     208                    DEVMAN_CONNECT_TO_DEVICE, handle);
     209        } else {
     210                phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,
     211                    DEVMAN_CONNECT_TO_DEVICE, handle);
     212        }
     213       
     214        return phone;
     215}
     216
     217int devman_parent_device_connect(device_handle_t handle, unsigned int flags)
     218{
     219        int phone;
     220       
     221        if (flags & IPC_FLAG_BLOCKING) {
     222                phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,
     223                    DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);
     224        } else {
     225                phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,
     226                    DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);
     227        }
     228       
     229        return phone;
     230}
     231
     232/** @}
     233 */
  • uspace/lib/libc/include/devman.h

    r57937dd r5cd136ab  
    4848int devman_child_device_register(const char *, match_id_list_t *, device_handle_t, device_handle_t *);
    4949
     50int devman_device_connect(device_handle_t handle, unsigned int flags);
     51int devman_parent_device_connect(device_handle_t handle, unsigned int flags);
     52
    5053
    5154#endif
  • uspace/lib/libc/include/ipc/dev_iface.h

    r57937dd r5cd136ab  
    7777                        int irq;                       
    7878                } intr;         
    79         };     
     79        } res
    8080} hw_resource_t;
    8181
    82 typedef struct {
     82typedef struct hw_resource_list {
    8383        size_t count;
    8484        hw_resource_t *resources;       
  • uspace/lib/libc/include/ipc/devman.h

    r57937dd r5cd136ab  
    116116        DEVMAN_DRIVER = 1,
    117117        DEVMAN_CLIENT,
    118         DEVMAN_CONNECT_TO_DEVICE
     118        DEVMAN_CONNECT_TO_DEVICE,
     119        DEVMAN_CONNECT_TO_PARENTS_DEVICE
    119120} devman_interface_t;
    120121
  • uspace/lib/libdrv/generic/driver.c

    r57937dd r5cd136ab  
    141141                return;
    142142        }
     143       
     144       
     145        // TODO - if the client is not a driver, check whether it is allowed to use the device
    143146
    144147        // TODO open the device (introduce some callbacks for opening and closing devices registered by the driver)
  • uspace/srv/devman/devman.c

    r57937dd r5cd136ab  
    506506        if (rc != EOK) {
    507507                // TODO handle error
    508                 return false;
     508                return;
    509509        }
    510510       
    511511        // TODO inspect return value (ret) to find out whether the device was successfully probed and added
    512512       
    513         return true;
     513        return;
    514514}
    515515
     
    618618 * @return true on success, false otherwise (insufficient resources etc.).
    619619 */
    620 bool insert_dev_node(dev_tree_t *tree, node_t *node, const char *dev_name, node_t *parent)
     620bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent)
    621621{
    622622        printf(NAME ": insert_dev_node\n");
     
    650650}
    651651
     652/**
     653 * Find device node with a specified path in the device tree.
     654 *
     655 * @param path the path of the device node in the device tree.
     656 * @param tree the device tree.
     657 *
     658 * @return the device node if it is present in the tree, NULL otherwise.
     659 */
     660node_t * find_dev_node_by_path(dev_tree_t *tree, char *path)
     661{
     662        node_t *dev = tree->root_node;
     663        char *rel_path = path;
     664        char *next_path_elem = NULL;
     665        size_t elem_size = 0;
     666        bool cont = '/' == rel_path[0];
     667       
     668        while (cont && NULL != dev) {           
     669                next_path_elem  = get_path_elem_end(rel_path+1);               
     670                if ('/' == next_path_elem[0]) {
     671                        cont = true;
     672                        next_path_elem[0] = 0;
     673                } else {
     674                        cont = false;
     675                }
     676               
     677                dev = find_node_child(dev, rel_path);           
     678               
     679                if (cont) {
     680                        next_path_elem[0] = '/';
     681                }
     682                rel_path = next_path_elem;             
     683        }
     684       
     685        return dev;
     686}
     687
     688/**
     689 * Find child device node with a specified name.
     690 *
     691 * @param parent the parent device node.
     692 * @param name the name of the child device node.
     693 *
     694 * @return the child device node.
     695 */
     696node_t *find_node_child(node_t *parent, const char *name)
     697{
     698        node_t *dev;
     699        link_t *link;
     700       
     701        fibril_mutex_lock(&parent->children_mutex);             
     702        link = parent->children.next;
     703       
     704        while (link != &parent->children) {
     705                dev = list_get_instance(link, node_t, sibling);
     706               
     707                if (0 == str_cmp(name, dev->name)) {
     708                        fibril_mutex_unlock(&parent->children_mutex);
     709                        return dev;                     
     710                }
     711        }       
     712       
     713        fibril_mutex_unlock(&parent->children_mutex);   
     714        return NULL;
     715}
     716
    652717/** @}
    653718 */
  • uspace/srv/devman/devman.h

    r57937dd r5cd136ab  
    238238}
    239239
     240/**
     241 * Delete a device node.
     242 *
     243 * @param node a device node structure.
     244 *
     245 */
    240246static inline void delete_dev_node(node_t *node)
    241247{
     
    263269}
    264270
     271node_t * find_dev_node_by_path(dev_tree_t *tree, char *path);
     272node_t *find_node_child(node_t *parent, const char *name);
     273
    265274// Device tree
    266275
    267276bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list);
    268277bool create_root_node(dev_tree_t *tree);
    269 bool insert_dev_node(dev_tree_t *tree, node_t *node, const char *dev_name, node_t *parent);
     278bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent);
    270279
    271280#endif
  • uspace/srv/devman/main.c

    r57937dd r5cd136ab  
    5151#include <ctype.h>
    5252#include <ipc/devman.h>
     53#include <ipc/driver.h>
    5354#include <thread.h>
    5455
     
    158159{
    159160        int ret = EOK;
    160         int i;
     161        size_t i;
    161162        for (i = 0; i < match_count; i++) {
    162163                if (EOK != (ret = devman_receive_match_id(match_ids))) {
     
    257258}
    258259
     260static void devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent) {
     261        device_handle_t handle;
     262        node_t *dev = find_dev_node(&device_tree, handle);
     263        if (NULL == dev) {
     264                ipc_answer_0(iid, ENOENT);
     265                return;
     266        }
     267       
     268        driver_t *driver = NULL;
     269       
     270        if (drv_to_parent) {
     271                driver = dev->parent->drv;
     272        } else {
     273                driver = dev->drv;             
     274        }
     275       
     276        if (NULL == driver) {           
     277                ipc_answer_0(iid, ENOENT);
     278                return;
     279        }
     280       
     281        int method;     
     282        if (drv_to_parent) {
     283                method = DRIVER_DRIVER;
     284        } else {
     285                method = DRIVER_CLIENT;
     286        }
     287       
     288        ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);     
     289}
     290
    259291/** Function for handling connections to device manager.
    260292 *
     
    269301        /*case DEVMAN_CLIENT:
    270302                devmap_connection_client(iid, icall);
    271                 break;
     303                break;*/
    272304        case DEVMAN_CONNECT_TO_DEVICE:
    273305                // Connect client to selected device
    274                 devmap_forward(iid, icall);
    275                 break;*/
     306                devman_forward(iid, icall, false);
     307                break;
     308        case DEVMAN_CONNECT_TO_PARENTS_DEVICE:
     309                // Connect client to selected device
     310                devman_forward(iid, icall, true);
     311                break;         
    276312        default:
    277313                /* No such interface */
  • uspace/srv/devman/util.c

    r57937dd r5cd136ab  
    6161        return res;
    6262}
     63
     64const char * get_path_elem_end(const char *path)
     65{
     66        while (0 != *path && '/' != *path) {
     67                path++;
     68        }
     69        return path;
     70}
  • uspace/srv/devman/util.h

    r57937dd r5cd136ab  
    3838
    3939char * get_abs_path(const char *base_path, const char *name, const char *ext);
     40const char * get_path_elem_end(const char *path);
    4041
    4142static inline bool skip_spaces(const char **buf)
  • uspace/srv/drivers/rootia32/rootia32.c

    r57937dd r5cd136ab  
    4949#include <devman.h>
    5050#include <ipc/devman.h>
     51#include <ipc/dev_iface.h>
    5152
    5253#define NAME "rootia32"
     54
     55typedef struct rootia32_dev_data {
     56        hw_resource_list_t hw_resources;       
     57} rootia32_dev_data_t;
    5358
    5459static bool rootia32_add_device(device_t *dev);
     
    6873};
    6974
    70 // TODO HW resources
    71 static bool rootia32_add_child(device_t *parent, const char *name, const char *str_match_id) {
     75static hw_resource_t pci_conf_regs = {
     76        .type = REGISTER,
     77        .res.reg = {
     78                .address = (void *)0xCF8,
     79                .size = 8,
     80                .endianness = LITTLE_ENDIAN     
     81        }       
     82};
     83
     84static rootia32_dev_data_t pci_data = {
     85        .hw_resources = {
     86                1,
     87                &pci_conf_regs
     88        }
     89};
     90
     91static bool rootia32_add_child(
     92        device_t *parent, const char *name, const char *str_match_id,
     93        rootia32_dev_data_t *drv_data)
     94{
    7295        printf(NAME ": adding new child device '%s'.\n", name);
    7396       
     
    81104       
    82105        child->name = name;
     106        child->driver_data = drv_data;
    83107       
    84108        // initialize match id list
     
    112136}
    113137
    114 static bool rootia32_add_children(dev)
     138static bool rootia32_add_children(device_t *dev)
    115139{
    116         return rootia32_add_child(dev, "pci0", "intel_pci");
     140        return rootia32_add_child(dev, "pci0", "intel_pci", &pci_data);
    117141}
    118142
Note: See TracChangeset for help on using the changeset viewer.