xref: /titanic_50/usr/src/lib/efcode/fcdriver/dma.c (revision 1e1ddd6cc98ab5af8293f7ebd132be62900730fd)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <strings.h>
32 #include <fcode/private.h>
33 #include <fcode/log.h>
34 
35 #include <fcdriver/fcdriver.h>
36 
37 
38 static void
39 do_dma_alloc(fcode_env_t *env)
40 {
41 	size_t size;
42 	void *p;
43 
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);
50 }
51 
52 static void
53 do_dma_free(fcode_env_t *env)
54 {
55 	void *p;
56 	size_t size;
57 
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);
62 
63 	free(p);
64 }
65 
66 static void
67 do_dma_map_in(fcode_env_t *env)
68 {
69 	fc_cell_t data;
70 	fstack_t va, len, cacheable;
71 	private_data_t *pd = DEVICE_PRIVATE(env);
72 	int error;
73 
74 	CHECK_DEPTH(env, 3, "dma-map-in");
75 	cacheable = POP(DS);
76 	len = POP(DS);
77 	va = POP(DS);
78 
79 	error = fc_run_priv(pd->common, "dma-map-in", 3, 1,
80 	    fc_int2cell(cacheable), fc_size2cell(len), fc_ptr2cell(va),
81 	    &data);
82 
83 	throw_from_fclib(env, error, "dma-map-in failed");
84 
85 	PUSH(DS, (fstack_t)data);
86 }
87 
88 static void
89 do_dma_map_out(fcode_env_t *env)
90 {
91 	fstack_t va, dva, len;
92 	private_data_t *pd = DEVICE_PRIVATE(env);
93 	int error;
94 
95 	CHECK_DEPTH(env, 3, "dma-map-out");
96 	len = POP(DS);
97 	dva = POP(DS);
98 	va = POP(DS);
99 
100 	error = fc_run_priv(pd->common, "dma-map-out", 3, 0, fc_size2cell(len),
101 	    fc_ptr2cell(dva), fc_ptr2cell(va));
102 
103 	throw_from_fclib(env, error, "dma-map-out failed");
104 }
105 
106 static void
107 do_dma_sync(fcode_env_t *env)
108 {
109 	CHECK_DEPTH(env, 3, "dma-sync");
110 	/* 3drop */
111 	DS -= 3;
112 }
113 
114 void
115 install_dma_methods(fcode_env_t *env)
116 {
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);
122 
123 }
124