00001
00002
00011
00012
00013
00014
00015
00038
00039 #include <l4/generic_io/libio.h>
00040
00041 #include <l4/dde_linux/dde.h>
00042 #include <l4/env/errno.h>
00043
00044
00045 #include <linux/ioport.h>
00046
00047 #include <l4/log/l4log.h>
00048
00049
00050 #include "__config.h"
00051 #include "internal.h"
00052
00057 static struct dde_region *regions = NULL;
00058
00070 struct resource *request_region(unsigned long start, unsigned long n,
00071 const char *name)
00072 {
00073 int err;
00074
00075 LOGdL(DEBUG_RES_TRACE, "io_addr=%p, size=%ld, name=\"%s\"", (void*)start, n, name);
00076 err = l4io_request_region((l4_addr_t) start, (l4_size_t) n);
00077
00078 if (err)
00079 {
00080 LOGdL(DEBUG_ERRORS, "Error: in l4io_request_region(0x%04lx, %ld) (%d)", start, n, err);
00081 return 0;
00082 }
00083
00084 return (struct resource *) 1;
00085 }
00086
00097 struct resource *request_mem_region(unsigned long start, unsigned long n,
00098 const char *name)
00099 {
00100 l4_addr_t vaddr;
00101
00102 LOGdL(DEBUG_RES_TRACE, "phys_addr=%p, size=%ld, name=\"%s\"", (void*)start, n, name);
00103 vaddr = l4io_request_mem_region((l4_addr_t) start, (l4_size_t) n, 0);
00104
00105 if (!vaddr)
00106 {
00107 LOGdL(DEBUG_ERRORS, "Error: in l4io_request_mem_region(%p, %ld)",
00108 (void*)start, n);
00109 return 0;
00110 }
00111
00112 dde_add_region(®ions, vaddr, start, n);
00113
00114 return (struct resource *) 1;
00115 }
00116
00123 void release_region(unsigned long start, unsigned long n)
00124 {
00125 int err;
00126
00127 LOGdL(DEBUG_RES_TRACE, "io_addr=%p, size=%ld", (void*)start, n);
00128 err = l4io_release_region((l4_addr_t) start, (l4_size_t) n);
00129
00130 if (err)
00131 LOG_Error("release_region(0x%04lx, %ld) failed (%d)", start, n, err);
00132 }
00133
00140 void release_mem_region(unsigned long start, unsigned long n)
00141 {
00142 int err;
00143
00144 LOGdL(DEBUG_RES_TRACE, "phys_addr=%p, size=%ld", (void*)start, n);
00145 err = l4io_release_mem_region((l4_addr_t) start, (l4_size_t) n);
00146
00147 if(err)
00148 {
00149 LOGdL(DEBUG_ERRORS, "Error: release_mem_region(%p, %ld) failed (%d)",
00150 (void*)start, n, err);
00151 return;
00152 }
00153
00154
00155 dde_remove_region(®ions, 0, start, n);
00156 }
00157
00165 int release_resource(struct resource *res)
00166 {
00167 LOG_Error("%s not implemented", __FUNCTION__);
00168
00169 return -L4_EINVAL;
00170 }
00171
00182 int check_region(unsigned long start, unsigned long n)
00183 {
00184 return 0;
00185 }
00186
00197 int check_mem_region(unsigned long start, unsigned long n)
00198 {
00199 return 0;
00200 }
00201
00212 void *ioremap(unsigned long phys_addr, unsigned long size)
00213 {
00214 struct dde_region *p;
00215 void *pp;
00216
00217 LOGdL(DEBUG_RES_TRACE, "phys_addr=%p, size=%ld", (void*)phys_addr, size);
00218
00219 #if !LATER
00220 #warning it is not later
00221
00222 p = regions;
00223 while (p)
00224 {
00225 if ((p->pa <= phys_addr) &&
00226 (p->pa + p->size >= phys_addr + size))
00227 {
00228 pp = (void *) (p->va + (phys_addr - p->pa));
00229 LOGd(DEBUG_RES, "ioremap: %p => %p", (void*)phys_addr, pp);
00230 return pp;
00231 }
00232 p = p->next;
00233 }
00234 #else
00235 if ((pp=(void*)__va(phys_addr)) && __va(phys_addr+size))
00236 {
00237 LOGd(DEBUG_RES, "ioremap: <%p-%p> => <%p-%p>",
00238 phys_addr, phys_addr+size, pp, pp+size);
00239 return pp;
00240 }
00241 #endif
00242
00243 LOG_Error("no ioremap address found for %p", (void*)phys_addr);
00244 return (void *) 0;
00245 }
00246
00258 void *ioremap_nocache(unsigned long phys_addr, unsigned long size)
00259 {
00260 LOGdL(DEBUG_RES_TRACE, "phys_addr=%p, size=%ld\n", (void*)phys_addr, size);
00261
00262 return ioremap(phys_addr, size);
00263 }
00264
00272 void iounmap(void *addr)
00273 {
00274 LOGdL(DEBUG_RES_TRACE, "addr=%p", addr);
00275 }