source: mainline/uspace/lib/usbhost/src/ddf_helpers.c@ 57c8fc9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 57c8fc9 was 57c8fc9, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

libusbhost: Move interrupt enabling to library.

Reduce code duplication.

  • Property mode set to 100644
File size: 18.5 KB
Line 
1/*
2 * Copyright (c) 2013 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libusbhost
30 * @{
31 */
32/** @file
33 *
34 */
35
36#include <usb_iface.h>
37#include <usb/classes/classes.h>
38#include <usb/debug.h>
39#include <usb/descriptor.h>
40#include <usb/request.h>
41#include <devman.h>
42#include <errno.h>
43#include <str_error.h>
44
45#include "ddf_helpers.h"
46
47#define CTRL_PIPE_MIN_PACKET_SIZE 8
48
49typedef struct usb_dev {
50 link_t link;
51 list_t devices;
52 fibril_mutex_t guard;
53 ddf_fun_t *fun;
54 usb_address_t address;
55 usb_speed_t speed;
56 usb_address_t tt_address;
57 unsigned port;
58} usb_dev_t;
59
60typedef struct hc_dev {
61 ddf_fun_t *ctl_fun;
62 hcd_t hcd;
63 usb_dev_t *root_hub;
64} hc_dev_t;
65
66static hc_dev_t *dev_to_hc_dev(ddf_dev_t *dev)
67{
68 return ddf_dev_data_get(dev);
69}
70
71hcd_t *dev_to_hcd(ddf_dev_t *dev)
72{
73 hc_dev_t *hc_dev = dev_to_hc_dev(dev);
74 if (!hc_dev) {
75 usb_log_error("Invalid HCD device.\n");
76 return NULL;
77 }
78 return &hc_dev->hcd;
79}
80
81
82static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port);
83static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port);
84
85
86/* DDF INTERFACE */
87
88/** Register endpoint interface function.
89 * @param fun DDF function.
90 * @param address USB address of the device.
91 * @param endpoint USB endpoint number to be registered.
92 * @param transfer_type Endpoint's transfer type.
93 * @param direction USB communication direction the endpoint is capable of.
94 * @param max_packet_size Maximu size of packets the endpoint accepts.
95 * @param interval Preferred timeout between communication.
96 * @return Error code.
97 */
98static int register_endpoint(
99 ddf_fun_t *fun, usb_endpoint_t endpoint,
100 usb_transfer_type_t transfer_type, usb_direction_t direction,
101 size_t max_packet_size, unsigned interval)
102{
103 assert(fun);
104 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
105 usb_dev_t *dev = ddf_fun_data_get(fun);
106 assert(hcd);
107 assert(dev);
108 const size_t size = max_packet_size;
109 const usb_target_t target =
110 {{.address = dev->address, .endpoint = endpoint}};
111
112 usb_log_debug("Register endpoint %d:%d %s-%s %zuB %ums.\n",
113 dev->address, endpoint, usb_str_transfer_type(transfer_type),
114 usb_str_direction(direction), max_packet_size, interval);
115
116 return hcd_add_ep(hcd, target, direction, transfer_type,
117 max_packet_size, size, dev->tt_address, dev->port);
118}
119
120/** Unregister endpoint interface function.
121 * @param fun DDF function.
122 * @param address USB address of the endpoint.
123 * @param endpoint USB endpoint number.
124 * @param direction Communication direction of the enpdoint to unregister.
125 * @return Error code.
126 */
127static int unregister_endpoint(
128 ddf_fun_t *fun, usb_endpoint_t endpoint, usb_direction_t direction)
129{
130 assert(fun);
131 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
132 usb_dev_t *dev = ddf_fun_data_get(fun);
133 assert(hcd);
134 assert(dev);
135 const usb_target_t target =
136 {{.address = dev->address, .endpoint = endpoint}};
137 usb_log_debug("Unregister endpoint %d:%d %s.\n",
138 dev->address, endpoint, usb_str_direction(direction));
139 return hcd_remove_ep(hcd, target, direction);
140}
141
142static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
143{
144 assert(fun);
145 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
146 usb_dev_t *dev = ddf_fun_data_get(fun);
147 assert(hcd);
148 assert(dev);
149
150 usb_log_debug("Device %d requested default address at %s speed\n",
151 dev->address, usb_str_speed(speed));
152 return hcd_reserve_default_address(hcd, speed);
153}
154
155static int release_default_address(ddf_fun_t *fun)
156{
157 assert(fun);
158 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
159 usb_dev_t *dev = ddf_fun_data_get(fun);
160 assert(hcd);
161 assert(dev);
162
163 usb_log_debug("Device %d released default address\n", dev->address);
164 return hcd_release_default_address(hcd);
165}
166
167static int device_enumerate(ddf_fun_t *fun, unsigned port)
168{
169 assert(fun);
170 ddf_dev_t *ddf_dev = ddf_fun_get_dev(fun);
171 usb_dev_t *dev = ddf_fun_data_get(fun);
172 assert(ddf_dev);
173 assert(dev);
174 usb_log_debug("Hub %d reported a new USB device on port: %u\n",
175 dev->address, port);
176 return hcd_ddf_new_device(ddf_dev, dev, port);
177}
178
179static int device_remove(ddf_fun_t *fun, unsigned port)
180{
181 assert(fun);
182 ddf_dev_t *ddf_dev = ddf_fun_get_dev(fun);
183 usb_dev_t *dev = ddf_fun_data_get(fun);
184 assert(ddf_dev);
185 assert(dev);
186 usb_log_debug("Hub `%s' reported removal of device on port %u\n",
187 ddf_fun_get_name(fun), port);
188 return hcd_ddf_remove_device(ddf_dev, dev, port);
189}
190
191/** Gets handle of the respective device.
192 *
193 * @param[in] fun Device function.
194 * @param[out] handle Place to write the handle.
195 * @return Error code.
196 */
197static int get_my_device_handle(ddf_fun_t *fun, devman_handle_t *handle)
198{
199 assert(fun);
200 if (handle)
201 *handle = ddf_fun_get_handle(fun);
202 return EOK;
203}
204
205/** Inbound communication interface function.
206 * @param fun DDF function.
207 * @param target Communication target.
208 * @param setup_data Data to use in setup stage (control transfers).
209 * @param data Pointer to data buffer.
210 * @param size Size of the data buffer.
211 * @param callback Function to call on communication end.
212 * @param arg Argument passed to the callback function.
213 * @return Error code.
214 */
215static int dev_read(ddf_fun_t *fun, usb_endpoint_t endpoint,
216 uint64_t setup_data, uint8_t *data, size_t size,
217 usbhc_iface_transfer_in_callback_t callback, void *arg)
218{
219 assert(fun);
220 usb_dev_t *usb_dev = ddf_fun_data_get(fun);
221 assert(usb_dev);
222 const usb_target_t target = {{
223 .address = usb_dev->address,
224 .endpoint = endpoint,
225 }};
226 return hcd_send_batch(dev_to_hcd(ddf_fun_get_dev(fun)), target,
227 USB_DIRECTION_IN, data, size, setup_data, callback, NULL, arg,
228 "READ");
229}
230
231/** Outbound communication interface function.
232 * @param fun DDF function.
233 * @param target Communication target.
234 * @param setup_data Data to use in setup stage (control transfers).
235 * @param data Pointer to data buffer.
236 * @param size Size of the data buffer.
237 * @param callback Function to call on communication end.
238 * @param arg Argument passed to the callback function.
239 * @return Error code.
240 */
241static int dev_write(ddf_fun_t *fun, usb_endpoint_t endpoint,
242 uint64_t setup_data, const uint8_t *data, size_t size,
243 usbhc_iface_transfer_out_callback_t callback, void *arg)
244{
245 assert(fun);
246 usb_dev_t *usb_dev = ddf_fun_data_get(fun);
247 assert(usb_dev);
248 const usb_target_t target = {{
249 .address = usb_dev->address,
250 .endpoint = endpoint,
251 }};
252 return hcd_send_batch(dev_to_hcd(ddf_fun_get_dev(fun)),
253 target, USB_DIRECTION_OUT, (uint8_t*)data, size, setup_data, NULL,
254 callback, arg, "WRITE");
255}
256
257/** USB device interface */
258static usb_iface_t usb_iface = {
259 .get_my_device_handle = get_my_device_handle,
260
261 .reserve_default_address = reserve_default_address,
262 .release_default_address = release_default_address,
263
264 .device_enumerate = device_enumerate,
265 .device_remove = device_remove,
266
267 .register_endpoint = register_endpoint,
268 .unregister_endpoint = unregister_endpoint,
269
270 .read = dev_read,
271 .write = dev_write,
272};
273
274/** Standard USB device interface) */
275static ddf_dev_ops_t usb_ops = {
276 .interfaces[USB_DEV_IFACE] = &usb_iface,
277};
278
279
280/* DDF HELPERS */
281
282#define GET_DEVICE_DESC(size) \
283{ \
284 .request_type = SETUP_REQUEST_TYPE_DEVICE_TO_HOST \
285 | (USB_REQUEST_TYPE_STANDARD << 5) \
286 | USB_REQUEST_RECIPIENT_DEVICE, \
287 .request = USB_DEVREQ_GET_DESCRIPTOR, \
288 .value = uint16_host2usb(USB_DESCTYPE_DEVICE << 8), \
289 .index = uint16_host2usb(0), \
290 .length = uint16_host2usb(size), \
291};
292
293#define SET_ADDRESS(address) \
294{ \
295 .request_type = SETUP_REQUEST_TYPE_HOST_TO_DEVICE \
296 | (USB_REQUEST_TYPE_STANDARD << 5) \
297 | USB_REQUEST_RECIPIENT_DEVICE, \
298 .request = USB_DEVREQ_SET_ADDRESS, \
299 .value = uint16_host2usb(address), \
300 .index = uint16_host2usb(0), \
301 .length = uint16_host2usb(0), \
302};
303
304static int hcd_ddf_add_device(ddf_dev_t *parent, usb_dev_t *hub_dev,
305 unsigned port, usb_address_t address, usb_speed_t speed, const char *name,
306 const match_id_list_t *mids)
307{
308 assert(parent);
309
310 char default_name[10] = { 0 }; /* usbxyz-ss */
311 if (!name) {
312 snprintf(default_name, sizeof(default_name) - 1,
313 "usb%u-%cs", address, usb_str_speed(speed)[0]);
314 name = default_name;
315 }
316
317 ddf_fun_t *fun = ddf_fun_create(parent, fun_inner, name);
318 if (!fun)
319 return ENOMEM;
320 usb_dev_t *info = ddf_fun_data_alloc(fun, sizeof(usb_dev_t));
321 if (!info) {
322 ddf_fun_destroy(fun);
323 return ENOMEM;
324 }
325 info->address = address;
326 info->speed = speed;
327 info->fun = fun;
328 info->port = port;
329 info->tt_address = hub_dev ? hub_dev->tt_address : -1;
330 link_initialize(&info->link);
331 list_initialize(&info->devices);
332 fibril_mutex_initialize(&info->guard);
333
334 if (hub_dev && hub_dev->speed == USB_SPEED_HIGH && usb_speed_is_11(speed))
335 info->tt_address = hub_dev->address;
336
337 ddf_fun_set_ops(fun, &usb_ops);
338 list_foreach(mids->ids, link, const match_id_t, mid) {
339 ddf_fun_add_match_id(fun, mid->id, mid->score);
340 }
341
342 int ret = ddf_fun_bind(fun);
343 if (ret != EOK) {
344 ddf_fun_destroy(fun);
345 return ret;
346 }
347
348 if (hub_dev) {
349 fibril_mutex_lock(&hub_dev->guard);
350 list_append(&info->link, &hub_dev->devices);
351 fibril_mutex_unlock(&hub_dev->guard);
352 } else {
353 hc_dev_t *hc_dev = dev_to_hc_dev(parent);
354 assert(hc_dev->root_hub == NULL);
355 hc_dev->root_hub = info;
356 }
357 return EOK;
358}
359
360#define ADD_MATCHID_OR_RETURN(list, sc, str, ...) \
361do { \
362 match_id_t *mid = malloc(sizeof(match_id_t)); \
363 if (!mid) { \
364 clean_match_ids(list); \
365 return ENOMEM; \
366 } \
367 char *id = NULL; \
368 int ret = asprintf(&id, str, ##__VA_ARGS__); \
369 if (ret < 0) { \
370 clean_match_ids(list); \
371 free(mid); \
372 return ENOMEM; \
373 } \
374 mid->score = sc; \
375 mid->id = id; \
376 add_match_id(list, mid); \
377} while (0)
378
379/* This is a copy of lib/usbdev/src/recognise.c */
380static int create_match_ids(match_id_list_t *l,
381 usb_standard_device_descriptor_t *d)
382{
383 assert(l);
384 assert(d);
385
386 if (d->vendor_id != 0) {
387 /* First, with release number. */
388 ADD_MATCHID_OR_RETURN(l, 100,
389 "usb&vendor=%#04x&product=%#04x&release=%x.%x",
390 d->vendor_id, d->product_id, (d->device_version >> 8),
391 (d->device_version & 0xff));
392
393 /* Next, without release number. */
394 ADD_MATCHID_OR_RETURN(l, 90, "usb&vendor=%#04x&product=%#04x",
395 d->vendor_id, d->product_id);
396 }
397
398 /* Class match id */
399 ADD_MATCHID_OR_RETURN(l, 50, "usb&class=%s",
400 usb_str_class(d->device_class));
401
402 /* As a last resort, try fallback driver. */
403 ADD_MATCHID_OR_RETURN(l, 10, "usb&fallback");
404
405 return EOK;
406
407}
408
409static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub,
410 unsigned port)
411{
412 assert(device);
413
414 hcd_t *hcd = dev_to_hcd(device);
415 assert(hcd);
416
417 hc_dev_t *hc_dev = dev_to_hc_dev(device);
418 assert(hc_dev);
419
420 fibril_mutex_lock(&hub->guard);
421
422 usb_dev_t *victim = NULL;
423
424 list_foreach(hub->devices, link, usb_dev_t, it) {
425 if (it->port == port) {
426 victim = it;
427 break;
428 }
429 }
430 if (victim && victim->port == port) {
431 list_remove(&victim->link);
432 fibril_mutex_unlock(&hub->guard);
433 const int ret = ddf_fun_unbind(victim->fun);
434 if (ret == EOK) {
435 ddf_fun_destroy(victim->fun);
436 hcd_release_address(hcd, victim->address);
437 } else {
438 usb_log_warning("Failed to unbind device `%s': %s\n",
439 ddf_fun_get_name(victim->fun), str_error(ret));
440 }
441 return EOK;
442 }
443 return ENOENT;
444}
445
446static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port)
447{
448 assert(device);
449
450 hcd_t *hcd = dev_to_hcd(device);
451 assert(hcd);
452
453 usb_speed_t speed = USB_SPEED_MAX;
454
455 /* This checks whether the default address is reserved and gets speed */
456 int ret = usb_bus_get_speed(&hcd->bus, USB_ADDRESS_DEFAULT, &speed);
457 if (ret != EOK) {
458 return ret;
459 }
460
461 static const usb_target_t default_target = {{
462 .address = USB_ADDRESS_DEFAULT,
463 .endpoint = 0,
464 }};
465
466 const usb_address_t address = hcd_request_address(hcd, speed);
467 if (address < 0)
468 return address;
469
470 const usb_target_t target = {{
471 .address = address,
472 .endpoint = 0,
473 }};
474
475 const usb_address_t tt_address = hub ? hub->tt_address : -1;
476
477 /* Add default pipe on default address */
478 ret = hcd_add_ep(hcd,
479 default_target, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
480 CTRL_PIPE_MIN_PACKET_SIZE, CTRL_PIPE_MIN_PACKET_SIZE,
481 tt_address, port);
482
483 if (ret != EOK) {
484 hcd_release_address(hcd, address);
485 return ret;
486 }
487
488 /* Get max packet size for default pipe */
489 usb_standard_device_descriptor_t desc = { 0 };
490 static const usb_device_request_setup_packet_t get_device_desc_8 =
491 GET_DEVICE_DESC(CTRL_PIPE_MIN_PACKET_SIZE);
492
493 // TODO CALLBACKS
494 ssize_t got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_IN,
495 &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8,
496 "read first 8 bytes of dev descriptor");
497
498 if (got != CTRL_PIPE_MIN_PACKET_SIZE) {
499 hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
500 hcd_release_address(hcd, address);
501 return got < 0 ? got : EOVERFLOW;
502 }
503
504 /* Register EP on the new address */
505 ret = hcd_add_ep(hcd, target, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
506 desc.max_packet_size, desc.max_packet_size, tt_address, port);
507 if (ret != EOK) {
508 hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
509 hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
510 hcd_release_address(hcd, address);
511 return ret;
512 }
513
514 /* Set new address */
515 const usb_device_request_setup_packet_t set_address =
516 SET_ADDRESS(target.address);
517
518 got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_OUT,
519 NULL, 0, *(uint64_t *)&set_address, "set address");
520
521 hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
522
523 if (got != 0) {
524 hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
525 hcd_release_address(hcd, address);
526 return got;
527 }
528
529 /* Get std device descriptor */
530 static const usb_device_request_setup_packet_t get_device_desc =
531 GET_DEVICE_DESC(sizeof(desc));
532
533 got = hcd_send_batch_sync(hcd, target, USB_DIRECTION_IN,
534 &desc, sizeof(desc), *(uint64_t *)&get_device_desc,
535 "read device descriptor");
536 if (ret != EOK) {
537 hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
538 hcd_release_address(hcd, target.address);
539 return got < 0 ? got : EOVERFLOW;
540 }
541
542 /* Create match ids from the device descriptor */
543 match_id_list_t mids;
544 init_match_ids(&mids);
545
546 ret = create_match_ids(&mids, &desc);
547 if (ret != EOK) {
548 hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
549 hcd_release_address(hcd, target.address);
550 return ret;
551 }
552
553 /* Register device */
554 ret = hcd_ddf_add_device(device, hub, port, address, speed, NULL, &mids);
555 clean_match_ids(&mids);
556 if (ret != EOK) {
557 hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
558 hcd_release_address(hcd, target.address);
559 }
560
561 return ret;
562}
563
564/** Announce root hub to the DDF
565 *
566 * @param[in] device Host controller ddf device
567 * @return Error code
568 */
569int hcd_ddf_setup_root_hub(ddf_dev_t *device)
570{
571 assert(device);
572 hcd_t *hcd = dev_to_hcd(device);
573 assert(hcd);
574
575 hcd_reserve_default_address(hcd, hcd->bus.max_speed);
576 const int ret = hcd_ddf_new_device(device, NULL, 0);
577 hcd_release_default_address(hcd);
578 return ret;
579}
580
581/** Initialize hc structures.
582 *
583 * @param[in] device DDF instance of the device to use.
584 * @param[in] max_speed Maximum supported USB speed.
585 * @param[in] bw available bandwidth.
586 * @param[in] bw_count Function to compute required ep bandwidth.
587 *
588 * @return Error code.
589 * This function does all the ddf work for hc driver.
590 */
591int hcd_ddf_setup_hc(ddf_dev_t *device, usb_speed_t max_speed,
592 size_t bw, bw_count_func_t bw_count)
593{
594 assert(device);
595
596 hc_dev_t *instance = ddf_dev_data_alloc(device, sizeof(hc_dev_t));
597 if (instance == NULL) {
598 usb_log_error("Failed to allocate HCD ddf structure.\n");
599 return ENOMEM;
600 }
601 instance->root_hub = NULL;
602 hcd_init(&instance->hcd, max_speed, bw, bw_count);
603
604 int ret = ENOMEM;
605 instance->ctl_fun = ddf_fun_create(device, fun_exposed, "ctl");
606 if (!instance->ctl_fun) {
607 usb_log_error("Failed to create HCD ddf fun.\n");
608 goto err_destroy_fun;
609 }
610
611 ret = ddf_fun_bind(instance->ctl_fun);
612 if (ret != EOK) {
613 usb_log_error("Failed to bind ctl_fun: %s.\n", str_error(ret));
614 goto err_destroy_fun;
615 }
616
617 ret = ddf_fun_add_to_category(instance->ctl_fun, USB_HC_CATEGORY);
618 if (ret != EOK) {
619 usb_log_error("Failed to add fun to category: %s.\n",
620 str_error(ret));
621 ddf_fun_unbind(instance->ctl_fun);
622 goto err_destroy_fun;
623 }
624
625 /* HC should be ok at this point (except it can't do anything) */
626 return EOK;
627
628err_destroy_fun:
629 ddf_fun_destroy(instance->ctl_fun);
630 instance->ctl_fun = NULL;
631 return ret;
632}
633
634void hcd_ddf_clean_hc(ddf_dev_t *device)
635{
636 assert(device);
637 hc_dev_t *hc = dev_to_hc_dev(device);
638 assert(hc);
639 const int ret = ddf_fun_unbind(hc->ctl_fun);
640 if (ret == EOK)
641 ddf_fun_destroy(hc->ctl_fun);
642}
643
644
645//TODO: Move this to generic ddf?
646/** Call the parent driver with a request to enable interrupts
647 *
648 * @param[in] device Device asking for interrupts
649 * @return Error code.
650 */
651int hcd_ddf_enable_interrupts(ddf_dev_t *device)
652{
653 assert(device);
654 async_sess_t *parent_sess =
655 devman_parent_device_connect(EXCHANGE_SERIALIZE,
656 ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
657 const bool enabled = hw_res_enable_interrupt(parent_sess);
658 async_hangup(parent_sess);
659
660 return enabled ? EOK : EIO;
661}
662
663int hcd_ddf_get_registers(ddf_dev_t *device, hw_res_list_parsed_t *hw_res)
664{
665 assert(device);
666 assert(hw_res);
667
668 async_sess_t *parent_sess =
669 devman_parent_device_connect(EXCHANGE_SERIALIZE,
670 ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
671 hw_res_list_parsed_init(hw_res);
672 const int ret = hw_res_get_list_parsed(parent_sess, hw_res, 0);
673 async_hangup(parent_sess);
674 return ret;
675}
676/**
677 * @}
678 */
Note: See TracBrowser for help on using the repository browser.