xref: /illumos-gate/usr/src/cmd/perl/contrib/Sun/Solaris/Intrs/Intrs.xs (revision fc80c0dfb0c877aee828d778ea32b77fcf7b1ef4)
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 2007 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 static int
46 open_dev(char *path)
47 {
48 	char intrpath[MAXPATHLEN];
49 
50 	(void) strcpy(intrpath, "/devices");
51 	(void) strcat(intrpath, path);
52 	(void) strcat(intrpath, ":intr");
53 	return (open(intrpath, O_RDWR));
54 }
55 
56 MODULE = Sun::Solaris::Intrs		PACKAGE = Sun::Solaris::Intrs
57 PROTOTYPES: ENABLE
58 
59 int
60 intrmove(path, ino, cpu, num_ino)
61 	char *path
62 	int ino
63 	int cpu
64 	int num_ino
65     INIT:
66 	int fd, ret;
67 	pcitool_intr_set_t iset;
68 
69     CODE:
70 	if ((fd = open_dev(path)) == -1) {
71 		XSRETURN_UNDEF;
72 	}
73 	iset.ino = ino;
74 	iset.cpu_id = cpu;
75 	iset.flags = (num_ino > 1) ? PCITOOL_INTR_SET_FLAG_GROUP : 0;
76 	iset.user_version = PCITOOL_VERSION;
77 
78 	ret = ioctl(fd, PCITOOL_DEVICE_SET_INTR, &iset);
79 
80 	if (ret == -1) {
81 		XSRETURN_UNDEF;
82 	}
83 	(void) close(fd);
84 	XSRETURN_YES;
85 
86 int
87 is_pcplusmp(path)
88 	char *path
89 
90     INIT:
91 	int fd, ret;
92 	pcitool_intr_info_t iinfo;
93 
94     CODE:
95 	if ((fd = open_dev(path)) == -1) {
96 		XSRETURN_UNDEF;
97 	}
98 	iinfo.user_version = PCITOOL_VERSION;
99 
100 	ret = ioctl(fd, PCITOOL_SYSTEM_INTR_INFO, &iinfo);
101 	(void) close(fd);
102 
103 	if (ret == -1) {
104 		XSRETURN_UNDEF;
105 	}
106 
107 	if (iinfo.ctlr_type == PCITOOL_CTLR_TYPE_PCPLUSMP) {
108 		XSRETURN_YES;
109 	}
110 
111 	XSRETURN_NO;
112