build: remove map.noexstk and map.noexdata (now default)
[unleashed.git] / usr / src / lib / efcode / jupiter / jupiter.c
blob27cd307054f00c0c7067e1f1d752e03671ee9086
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <strings.h>
30 #include <fcode/private.h>
31 #include <fcode/log.h>
33 #include <fcdriver/fcdriver.h>
35 #include <sys/opl_cfg.h>
37 /* VA for HardWare Descriptor */
38 static hwd_cmu_chan_t hwd_va_cmu;
39 static hwd_leaf_t hwd_va_pci;
41 /* Macro to get I/O portid */
42 #define DO_GET_IO_PORTID(env, lo, hi, portid) \
43 PUSH(DS, lo); \
44 PUSH(DS, hi); \
45 do_get_io_portid(env); \
46 portid = (uint32_t)POP(DS)
48 fstack_t
49 mem_map_in(fcode_env_t *env, fstack_t hi, fstack_t lo, fstack_t len)
51 private_data_t *pdp = DEVICE_PRIVATE(env);
52 fc_cell_t virt;
53 fstack_t mcookie = NULL;
54 char *service = "map-in";
55 int error;
56 int offset = 0;
59 * The calculation of the offset, lo and len are left here
60 * due to historical precedence.
63 offset = lo & PAGEOFFSET;
64 lo &= PAGEMASK;
65 len = (len + offset + PAGEOFFSET) & PAGEMASK;
67 error = fc_run_priv(pdp->common, service, 3, 1, fc_size2cell(len),
68 fc_uint32_t2cell(hi), fc_uint32_t2cell(lo), &virt);
70 if (error)
71 throw_from_fclib(env, 1, "jupiter:%s: failed\n", service);
73 mcookie = mapping_to_mcookie(virt, len, NULL, NULL);
75 if (mcookie == NULL)
76 throw_from_fclib(env, 1,
77 "jupiter:%s: mapping_to_mcookie failed\n", service);
79 mcookie += offset;
81 debug_msg(DEBUG_REG_ACCESS, "jupiter:%s: %llx -> %x\n", service,
82 (long long)virt, (uint32_t)mcookie);
84 return (mcookie);
87 static void
88 mem_map_out(fcode_env_t *env, fstack_t mcookie, fstack_t len)
90 private_data_t *pdp = DEVICE_PRIVATE(env);
91 fc_cell_t virt;
92 char *service = "map-out";
93 int error;
94 int offset;
97 * The calculation of the offset, lo and len are left here
98 * due to historical precedence.
101 offset = mcookie & PAGEOFFSET;
102 mcookie &= PAGEMASK;
103 len = (len + offset + PAGEOFFSET) & PAGEMASK;
105 if (!is_mcookie(mcookie)) {
106 log_message(MSG_ERROR, "jupiter:%s: %x not an mcookie!\n",
107 service, (int)mcookie);
108 virt = mcookie;
109 } else {
110 virt = mcookie_to_addr(mcookie);
111 debug_msg(DEBUG_REG_ACCESS, "jupiter:%s: %x -> %llx\n",
112 service, (int)mcookie, (long long)virt);
113 delete_mapping(mcookie);
116 error = fc_run_priv(pdp->common, service, 2, 0,
117 fc_size2cell(len), virt);
118 if (error)
119 log_message(MSG_ERROR, "jupiter:%s: failed\n", service);
122 static void
123 do_map_in(fcode_env_t *env)
125 fstack_t phi, plo, len, addr;
127 CHECK_DEPTH(env, 3, "jupiter:map-in");
128 len = POP(DS);
129 phi = POP(DS);
130 plo = POP(DS);
131 addr = mem_map_in(env, phi, plo, len);
132 PUSH(DS, addr);
135 static void
136 do_map_out(fcode_env_t *env)
138 fstack_t addr, len;
140 CHECK_DEPTH(env, 2, "jupiter:map-out");
141 len = POP(DS);
142 addr = POP(DS);
143 mem_map_out(env, addr, len);
146 static void
147 do_get_io_portid(fcode_env_t *env)
149 fstack_t phi, plo;
150 unsigned int portid, lsb, ch, leaf;
152 CHECK_DEPTH(env, 2, "jupiter:get-portid");
154 phi = POP(DS);
155 plo = POP(DS);
157 lsb = OPL_ADDR_TO_LSB(phi);
158 ch = OPL_ADDR_TO_CHANNEL(phi);
159 leaf = OPL_ADDR_TO_LEAF(phi, plo);
161 portid = OPL_IO_PORTID(lsb, ch, leaf);
163 debug_msg(DEBUG_REG_ACCESS, "jupiter:get-portid ( %x %x ) -> %x\n",
164 (int)phi, (int)plo, (int)portid);
165 PUSH(DS, portid);
168 static void
169 do_encode_unit(fcode_env_t *env)
171 char enc_buf[64];
172 fstack_t hi, lo;
173 uint32_t id;
174 long long off;
176 CHECK_DEPTH(env, 2, "jupiter:encode-unit");
178 hi = POP(DS);
179 lo = POP(DS);
180 off = (long long)(((hi & 0x1F) << 32) | lo);
182 /* Convert physical address to portid */
183 DO_GET_IO_PORTID(env, lo, hi, id);
185 if (off) {
186 (void) sprintf(enc_buf, "%x,%llx", id, off);
187 } else {
188 (void) sprintf(enc_buf, "%x", id);
191 debug_msg(DEBUG_REG_ACCESS, "jupiter:encode_unit ( %x %x ) -> '%s'\n",
192 (uint32_t)hi, (uint32_t)lo, enc_buf);
194 push_a_string(env, STRDUP(enc_buf));
197 static void
198 do_decode_unit(fcode_env_t *env)
200 uint32_t hi;
201 long long lo;
202 unsigned int portid, lsb, ch;
203 char *buf;
205 CHECK_DEPTH(env, 2, "jupiter:decode-unit");
207 buf = pop_a_string(env, NULL);
208 if (sscanf(buf, "%x,%llx", &portid, &lo) != 2) {
209 if (sscanf(buf, "%x", &portid) != 1) {
210 throw_from_fclib(env, 1, "jupiter:decode_unit:%s",
211 buf);
213 lo = 0;
216 lsb = OPL_IO_PORTID_TO_LSB(portid);
217 ch = OPL_PORTID_TO_CHANNEL(portid);
218 hi = OPL_ADDR_HI(lsb, ch);
220 debug_msg(DEBUG_REG_ACCESS,
221 "jupiter:decode_unit ( '%s' ) -> %x %llx\n", buf, hi, lo);
223 PUSH(DS, (fstack_t)lo);
224 PUSH(DS, (fstack_t)hi);
227 static void
228 do_device_id(fcode_env_t *env)
230 common_data_t *cdp = COMMON_PRIVATE(env);
231 char *buf = NULL;
232 uint32_t hi;
233 long long lo;
234 uint32_t portid, ch, leaf;
236 CHECK_DEPTH(env, 2, "jupiter:device-id");
238 hi = POP(DS);
239 lo = POP(DS);
241 portid = 0;
242 if (cdp && cdp->fc.unit_address &&
243 ((buf = strdup(cdp->fc.unit_address)) != NULL)) {
245 * Get portid number from unit_address
246 * Because of no leaf information in physical address
248 if (sscanf(buf, "%x,%llx", &portid, &lo) != 2) {
249 if (sscanf(buf, "%x", &portid) != 1) {
250 throw_from_fclib(env, 1,
251 "jupiter:do_device_id: invalid %s", buf);
254 } else {
256 * Non existence unit_address case.
257 * Convert physical address to portid.
259 throw_from_fclib(env, 1,
260 "jupiter:do_device_id: failed unit address");
261 DO_GET_IO_PORTID(env, lo, hi, portid);
264 debug_msg(DEBUG_FIND_FCODE,
265 "jupiter:do_device_id:(%x,%llx)\n", portid, lo);
267 /* Pick up each ID from portid */
268 ch = OPL_PORTID_TO_CHANNEL(portid);
269 leaf = OPL_PORTID_TO_LEAF(portid);
271 if (ch == OPL_CMU_CHANNEL) {
273 * CMU-CH: PCICMU CHANNEL
275 debug_msg(DEBUG_FIND_FCODE,
276 "jupiter:do_device_id:cmu-ch\n");
277 push_a_string(env, "cmu-ch");
278 } else if (OPL_OBERON_CHANNEL(ch) && OPL_VALID_LEAF(leaf)) {
280 * PCI-CH: Oberon Leaves CHANNEL
282 if (leaf) {
283 /* Leaf B */
284 debug_msg(DEBUG_FIND_FCODE,
285 "jupiter:do_device_id:jup-oberon-pci1\n");
286 push_a_string(env, "jup-oberon-pci1");
287 } else {
288 /* Leaf A */
289 debug_msg(DEBUG_FIND_FCODE,
290 "jupiter:do_device_id:jup-oberon-pci0\n");
291 push_a_string(env, "jup-oberon-pci0");
293 } else {
294 /* Not matched to any channels */
295 throw_from_fclib(env, 1,
296 "jupiter:do_device_id: invalid portid %x", portid);
297 push_a_string(env, "");
300 /* Free the duplicated buf */
301 free(buf);
304 static void
305 do_get_hwd_va(fcode_env_t *env)
307 private_data_t *pdp = DEVICE_PRIVATE(env);
308 char *service = "get-hwd-va";
309 char *buf;
310 uint32_t portid = 0;
311 int ch;
312 int error;
313 fc_cell_t status;
314 void *hwd_va;
316 CHECK_DEPTH(env, 2, "jupiter:get-hwd-va");
318 /* Get a portid with string format */
319 buf = pop_a_string(env, NULL);
321 /* Convert to the integer from the string */
322 if (sscanf(buf, "%x", &portid) != 1) {
323 throw_from_fclib(env, 1, "jupiter:%s: invalid portid",
324 service);
327 ch = OPL_PORTID_TO_CHANNEL(portid);
328 if (!OPL_VALID_CHANNEL(ch)) {
329 throw_from_fclib(env, 1, "jupiter:%s: invalid poritd",
330 service);
331 hwd_va = 0;
332 goto out;
335 if (ch == OPL_CMU_CHANNEL) {
336 hwd_va = (void *)&hwd_va_cmu;
337 } else {
338 hwd_va = (void *)&hwd_va_pci;
342 * Get the virtual address of hwd specified with portid.
344 error = fc_run_priv(pdp->common, service, 2, 1,
345 fc_uint32_t2cell(portid), fc_ptr2cell(hwd_va), &status);
347 if (error || !status)
348 throw_from_fclib(env, 1, "jupiter:%s: failed\n", service);
350 out:
351 PUSH(DS, (fstack_t)hwd_va);
354 static void
355 do_get_intrp_name(fcode_env_t *env)
358 * Just pass the "eFCode" string.
361 debug_msg(DEBUG_FIND_FCODE,
362 "jupiter: do_get_intrp_name: eFCode\n");
364 push_a_string(env, "eFCode");
367 static void
368 do_master_interrupt(fcode_env_t *env)
370 private_data_t *pdp = DEVICE_PRIVATE(env);
371 char *service = "master-interrupt";
372 int portid;
373 token_t xt;
374 int error;
375 fc_cell_t status;
377 CHECK_DEPTH(env, 2, "jupiter:master-interrupt");
378 portid = POP(DS);
379 xt = POP(DS);
382 * Install the master interrupt handler for this port id.
384 error = fc_run_priv(pdp->common, service, 2, 1,
385 fc_uint32_t2cell(portid), fc_uint32_t2cell(xt), &status);
387 if (error || !status)
388 throw_from_fclib(env, 1, "jupiter:%s: failed\n", service);
390 PUSH(DS, FALSE);
392 debug_msg(DEBUG_REG_ACCESS,
393 "jupiter:master-interrupt ( %x %x ) -> %x\n",
394 portid, xt, (int)FALSE);
397 static void
398 do_register_vector_entry(fcode_env_t *env)
400 int ign, ino, level;
402 CHECK_DEPTH(env, 3, "jupiter:register-vector-entry");
403 ign = POP(DS);
404 ino = POP(DS);
405 level = POP(DS);
407 PUSH(DS, FALSE);
408 debug_msg(DEBUG_REG_ACCESS,
409 "jupiter:register-vector-entry ( %x %x %x ) -> %x\n",
410 ign, ino, level, (int)FALSE);
413 static void
414 do_get_interrupt_target(fcode_env_t *env)
416 int mid = -1;
418 PUSH(DS, mid);
419 debug_msg(DEBUG_REG_ACCESS,
420 "jupiter:get-interrupt-target ( ) -> %x\n", mid);
424 #pragma init(_init)
426 static void
427 _init(void)
429 fcode_env_t *env = initial_env;
431 ASSERT(env);
432 ASSERT(env->current_device);
433 NOTICE;
435 create_int_prop(env, "#address-cells", 2);
437 FORTH(0, "map-in", do_map_in);
438 FORTH(0, "map-out", do_map_out);
439 FORTH(0, "get-portid", do_get_io_portid);
440 FORTH(0, "decode-unit", do_decode_unit);
441 FORTH(0, "encode-unit", do_encode_unit);
442 FORTH(0, "device-id", do_device_id);
443 FORTH(0, "get-hwd-va", do_get_hwd_va);
444 FORTH(0, "get-fcinterp-name", do_get_intrp_name);
445 FORTH(0, "master-interrupt", do_master_interrupt);
446 FORTH(0, "register-vector-entry", do_register_vector_entry);
447 FORTH(0, "get-interrupt-target", do_get_interrupt_target);