8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / efcode / fcdriver / dma.c
blob669a681905ea8d8601563b4e77e5089e13919559
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <strings.h>
32 #include <fcode/private.h>
33 #include <fcode/log.h>
35 #include <fcdriver/fcdriver.h>
38 static void
39 do_dma_alloc(fcode_env_t *env)
41 size_t size;
42 void *p;
44 CHECK_DEPTH(env, 1, "dma-alloc");
45 size = (size_t) POP(DS);
46 p = valloc(size);
47 debug_msg(DEBUG_REG_ACCESS, "dma-alloc ( %x ) -> %p\n", (int)size, p);
48 throw_from_fclib(env, (p == 0), "dma-alloc failed");
49 PUSH(DS, (fstack_t) p);
52 static void
53 do_dma_free(fcode_env_t *env)
55 void *p;
56 size_t size;
58 CHECK_DEPTH(env, 2, "dma-free");
59 size = POP(DS);
60 p = (void *) POP(DS);
61 debug_msg(DEBUG_REG_ACCESS, "dma-free ( %p %x )\n", p, (int)size);
63 free(p);
66 static void
67 do_dma_map_in(fcode_env_t *env)
69 fc_cell_t data;
70 fstack_t va, len, cacheable;
71 private_data_t *pd = DEVICE_PRIVATE(env);
72 int error;
74 CHECK_DEPTH(env, 3, "dma-map-in");
75 cacheable = POP(DS);
76 len = POP(DS);
77 va = POP(DS);
79 error = fc_run_priv(pd->common, "dma-map-in", 3, 1,
80 fc_int2cell(cacheable), fc_size2cell(len), fc_ptr2cell(va),
81 &data);
83 throw_from_fclib(env, error, "dma-map-in failed");
85 PUSH(DS, (fstack_t)data);
88 static void
89 do_dma_map_out(fcode_env_t *env)
91 fstack_t va, dva, len;
92 private_data_t *pd = DEVICE_PRIVATE(env);
93 int error;
95 CHECK_DEPTH(env, 3, "dma-map-out");
96 len = POP(DS);
97 dva = POP(DS);
98 va = POP(DS);
100 error = fc_run_priv(pd->common, "dma-map-out", 3, 0, fc_size2cell(len),
101 fc_ptr2cell(dva), fc_ptr2cell(va));
103 throw_from_fclib(env, error, "dma-map-out failed");
106 static void
107 do_dma_sync(fcode_env_t *env)
109 CHECK_DEPTH(env, 3, "dma-sync");
110 /* 3drop */
111 DS -= 3;
114 void
115 install_dma_methods(fcode_env_t *env)
117 FORTH(0, "dma-alloc", do_dma_alloc);
118 FORTH(0, "dma-free", do_dma_free);
119 FORTH(0, "dma-map-in", do_dma_map_in);
120 FORTH(0, "dma-map-out", do_dma_map_out);
121 FORTH(0, "dma-sync", do_dma_sync);