]> rtime.felk.cvut.cz Git - l4.git/blobdiff - l4/pkg/libio-io/lib/src/io.cc
update
[l4.git] / l4 / pkg / libio-io / lib / src / io.cc
index 36a318a2e089910977ca693e5134d2afdea8f454..5b1bc5596bc56ab6b23a9c123d7d8c8cd3c3daeb 100644 (file)
@@ -62,7 +62,7 @@ __internal_l4io_init()
       vbus() = L4Re::Env::env()->get_cap<void>("vbus");
       if (!vbus().is_valid())
        {
-         printf("libio: Warning: Query of 'vbus' failed with!\n");
+         printf("libio: Warning: Query of 'vbus' failed!\n");
          return;
        }
 
@@ -106,14 +106,14 @@ long
 l4io_request_irq(int irqnum, l4_cap_idx_t irq_cap)
 {
   L4::Cap<L4::Irq> irq(irq_cap);
-  long ret = l4_ipc_error(L4Re::Env::env()->factory()->create_irq(irq), l4_utcb());
-  if (ret) {
+  long ret = l4_error(L4Re::Env::env()->factory()->create_irq(irq));
+  if (ret < 0) {
       printf("Create irq failed with %ld\n", ret);
       return ret;
   }
 
-  ret = l4_ipc_error(icu()->bind(irqnum, irq), l4_utcb());
-  if (ret) {
+  ret = l4_error(icu()->bind(irqnum, irq));
+  if (ret < 0) {
       printf("Bind irq to icu failed with %ld\n", ret);
       return ret;
   }
@@ -149,11 +149,23 @@ static long
 __map_iomem(l4_addr_t phys, l4_addr_t* virt, unsigned long size, int flags)
 {
   Cap<L4Re::Dataspace> iomem = L4::cap_cast<L4Re::Dataspace>(vbus());
+  unsigned char align = L4_PAGESHIFT;
+
+  if (size >= L4_SUPERPAGESIZE)
+    align = L4_SUPERPAGESHIFT;
+
+  unsigned long rmflags = 0;
+
+  if (flags & L4IO_MEM_EAGER_MAP)
+    rmflags |= L4Re::Rm::Eager_map;
 
-  int res = L4Re::Env::env()->rm()->attach(virt, size,
-                               *virt
-                                ? (flags & L4IO_MEM_USE_RESERVED_AREA ? L4Re::Rm::In_area : 0)
-                                : L4Re::Rm::Search_addr, iomem, phys);
+  if (*virt && (flags & L4IO_MEM_USE_RESERVED_AREA))
+    rmflags |= L4Re::Rm::In_area;
+
+  if (!*virt)
+    rmflags |= L4Re::Rm::Search_addr;
+
+  int res = L4Re::Env::env()->rm()->attach(virt, size, rmflags, iomem, phys, align);
   if (res)
     {
       printf("Cannot attach iomem to virtual address %lx with size %lx: %s(%d).\n",
@@ -324,3 +336,26 @@ l4io_request_all_ioports(void)
 {
   __l4io_get_all_ports(l4io_get_root_device());
 }
+
+int
+l4io_has_resource(enum l4io_resource_types_t type,
+                  l4vbus_paddr_t start, l4vbus_paddr_t end)
+{
+  l4io_device_handle_t dh = l4io_get_root_device();
+  l4io_device_t dev;
+  l4io_resource_handle_t reshandle;
+
+  while (1)
+    {
+      l4io_resource_t res;
+
+      if (l4io_iterate_devices(&dh, &dev, &reshandle))
+        break;
+
+      if (dev.num_resources)
+        while (!l4io_lookup_resource(dh, type, &reshandle, &res))
+          if (start >= res.start && end <= res.end)
+            return 1;
+    }
+  return 0;
+}