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]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
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) \
45 do_get_io_portid(env); \
46 portid = (uint32_t)POP(DS)
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
);
53 fstack_t mcookie
= NULL
;
54 char *service
= "map-in";
59 * The calculation of the offset, lo and len are left here
60 * due to historical precedence.
63 offset
= lo
& PAGEOFFSET
;
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
);
71 throw_from_fclib(env
, 1, "jupiter:%s: failed\n", service
);
73 mcookie
= mapping_to_mcookie(virt
, len
, NULL
, NULL
);
76 throw_from_fclib(env
, 1,
77 "jupiter:%s: mapping_to_mcookie failed\n", service
);
81 debug_msg(DEBUG_REG_ACCESS
, "jupiter:%s: %llx -> %x\n", service
,
82 (long long)virt
, (uint32_t)mcookie
);
88 mem_map_out(fcode_env_t
*env
, fstack_t mcookie
, fstack_t len
)
90 private_data_t
*pdp
= DEVICE_PRIVATE(env
);
92 char *service
= "map-out";
97 * The calculation of the offset, lo and len are left here
98 * due to historical precedence.
101 offset
= mcookie
& PAGEOFFSET
;
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
);
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
);
119 log_message(MSG_ERROR
, "jupiter:%s: failed\n", service
);
123 do_map_in(fcode_env_t
*env
)
125 fstack_t phi
, plo
, len
, addr
;
127 CHECK_DEPTH(env
, 3, "jupiter:map-in");
131 addr
= mem_map_in(env
, phi
, plo
, len
);
136 do_map_out(fcode_env_t
*env
)
140 CHECK_DEPTH(env
, 2, "jupiter:map-out");
143 mem_map_out(env
, addr
, len
);
147 do_get_io_portid(fcode_env_t
*env
)
150 unsigned int portid
, lsb
, ch
, leaf
;
152 CHECK_DEPTH(env
, 2, "jupiter:get-portid");
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
);
169 do_encode_unit(fcode_env_t
*env
)
176 CHECK_DEPTH(env
, 2, "jupiter:encode-unit");
180 off
= (long long)(((hi
& 0x1F) << 32) | lo
);
182 /* Convert physical address to portid */
183 DO_GET_IO_PORTID(env
, lo
, hi
, id
);
186 (void) sprintf(enc_buf
, "%x,%llx", id
, off
);
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
));
198 do_decode_unit(fcode_env_t
*env
)
202 unsigned int portid
, lsb
, ch
;
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",
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
);
228 do_device_id(fcode_env_t
*env
)
230 common_data_t
*cdp
= COMMON_PRIVATE(env
);
234 uint32_t portid
, ch
, leaf
;
236 CHECK_DEPTH(env
, 2, "jupiter:device-id");
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
);
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
284 debug_msg(DEBUG_FIND_FCODE
,
285 "jupiter:do_device_id:jup-oberon-pci1\n");
286 push_a_string(env
, "jup-oberon-pci1");
289 debug_msg(DEBUG_FIND_FCODE
,
290 "jupiter:do_device_id:jup-oberon-pci0\n");
291 push_a_string(env
, "jup-oberon-pci0");
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 */
305 do_get_hwd_va(fcode_env_t
*env
)
307 private_data_t
*pdp
= DEVICE_PRIVATE(env
);
308 char *service
= "get-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",
327 ch
= OPL_PORTID_TO_CHANNEL(portid
);
328 if (!OPL_VALID_CHANNEL(ch
)) {
329 throw_from_fclib(env
, 1, "jupiter:%s: invalid poritd",
335 if (ch
== OPL_CMU_CHANNEL
) {
336 hwd_va
= (void *)&hwd_va_cmu
;
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
);
351 PUSH(DS
, (fstack_t
)hwd_va
);
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");
368 do_master_interrupt(fcode_env_t
*env
)
370 private_data_t
*pdp
= DEVICE_PRIVATE(env
);
371 char *service
= "master-interrupt";
377 CHECK_DEPTH(env
, 2, "jupiter:master-interrupt");
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
);
392 debug_msg(DEBUG_REG_ACCESS
,
393 "jupiter:master-interrupt ( %x %x ) -> %x\n",
394 portid
, xt
, (int)FALSE
);
398 do_register_vector_entry(fcode_env_t
*env
)
402 CHECK_DEPTH(env
, 3, "jupiter:register-vector-entry");
408 debug_msg(DEBUG_REG_ACCESS
,
409 "jupiter:register-vector-entry ( %x %x %x ) -> %x\n",
410 ign
, ino
, level
, (int)FALSE
);
414 do_get_interrupt_target(fcode_env_t
*env
)
419 debug_msg(DEBUG_REG_ACCESS
,
420 "jupiter:get-interrupt-target ( ) -> %x\n", mid
);
429 fcode_env_t
*env
= initial_env
;
432 ASSERT(env
->current_device
);
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
);