xref: /illumos-gate/usr/src/cmd/perl/contrib/Sun/Solaris/Intrs/Intrs.xs (revision cbab2b2687744cbfdc12fae90f8088127a0b266c)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <sys/pci.h>
32 #include <fcntl.h>
33 #include <unistd.h>
34 #include <stropts.h>
35 #include <stdio.h>
36 #include <errno.h>
37 
38 /* Non-shipping header - see Makefile.PL */
39 #include <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