xref: /illumos-gate/usr/src/cmd/perl/contrib/Sun/Solaris/Intrs/Intrs.xs (revision 032624d56c174c5c55126582b32e314a6af15522)
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 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <sys/pci.h>
33 #include <fcntl.h>
34 #include <unistd.h>
35 #include <stropts.h>
36 #include <stdio.h>
37 #include <errno.h>
38 
39 #include "../../../../../../../uts/common/sys/pci_tools.h"
40 
41 #include "EXTERN.h"
42 #include "perl.h"
43 #include "XSUB.h"
44 
45 MODULE = Sun::Solaris::Intrs		PACKAGE = Sun::Solaris::Intrs
46 PROTOTYPES: ENABLE
47 
48 int
49 intrmove(path, ino, cpu)
50 	char *path
51 	int ino
52 	int cpu
53     INIT:
54 	int i, ret;
55 	pcitool_intr_set_t iset;
56 	static int fd = -1;
57 	static char intrpath[MAXPATHLEN];
58 
59     CODE:
60 	if (fd == -1 || strcmp(path, intrpath)) {
61 		(void) strcpy(intrpath, "/devices");
62 		(void) strcat(intrpath, path);
63 		(void) strcat(intrpath, ":intr");
64 		if (fd != -1)
65 			(void) close(fd);
66 		fd = open(intrpath, O_RDONLY);
67 		if (fd == -1) {
68 			XSRETURN_UNDEF;
69 		}
70 	}
71 	iset.ino = ino;
72 	iset.cpu_id = cpu;
73 	iset.user_version = PCITOOL_USER_VERSION;
74 
75 	ret = ioctl(fd, PCITOOL_DEVICE_SET_INTR, &iset);
76 
77 	if (ret == -1) {
78 		XSRETURN_UNDEF;
79 	}
80 	XSRETURN_YES;
81