mem_util.c (d00f0155) mem_util.c (31e37bb4)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
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.
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance 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/*
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/*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
22 * 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 <mem.h>
30#include <fcntl.h>
31#include <unistd.h>
32#include <errno.h>
33#include <sys/mem.h>
34#include <fm/fmd_fmri.h>
35
23 * Use is subject to license terms.
24 */
25
26#pragma ident "%Z%%M% %I% %E% SMI"
27
28#include <mem.h>
29#include <fcntl.h>
30#include <unistd.h>
31#include <errno.h>
32#include <sys/mem.h>
33#include <fm/fmd_fmri.h>
34
35#ifdef sparc
36#include <sys/fm/ldom.h>
37extern ldom_hdl_t *mem_scheme_lhp;
38#endif
39
36void
37mem_strarray_free(char **arr, size_t dim)
38{
39 int i;
40
41 for (i = 0; i < dim; i++) {
42 if (arr[i] != NULL)
43 fmd_fmri_strfree(arr[i]);
44 }
45 fmd_fmri_free(arr, sizeof (char *) * dim);
46}
47
48int
49mem_page_cmd(int cmd, nvlist_t *nvl)
50{
40void
41mem_strarray_free(char **arr, size_t dim)
42{
43 int i;
44
45 for (i = 0; i < dim; i++) {
46 if (arr[i] != NULL)
47 fmd_fmri_strfree(arr[i]);
48 }
49 fmd_fmri_free(arr, sizeof (char *) * dim);
50}
51
52int
53mem_page_cmd(int cmd, nvlist_t *nvl)
54{
55#ifdef sparc
56 int rc;
57
58 if (cmd == MEM_PAGE_ISRETIRED || cmd == MEM_PAGE_FMRI_ISRETIRED) {
59 rc = ldom_fmri_status(mem_scheme_lhp, nvl);
60 } else if (cmd == MEM_PAGE_RETIRE || cmd == MEM_PAGE_FMRI_RETIRE) {
61 rc = ldom_fmri_retire(mem_scheme_lhp, nvl);
62 } else {
63 errno = ENOTSUP;
64 return (-1);
65 }
66
67 if (rc > -1) {
68 return (0);
69 } else {
70 errno = EIO;
71 return (-1);
72 }
73#else
51 mem_page_t mpage;
52 char *fmribuf;
53 size_t fmrisz;
54 int fd, rc, err;
55
56 if ((fd = open("/dev/mem", O_RDONLY)) < 0)
57 return (-1); /* errno is set for us */
58

--- 22 unchanged lines hidden (view full) ---

81 (void) close(fd);
82
83 if (rc < 0) {
84 errno = err;
85 return (-1);
86 }
87
88 return (0);
74 mem_page_t mpage;
75 char *fmribuf;
76 size_t fmrisz;
77 int fd, rc, err;
78
79 if ((fd = open("/dev/mem", O_RDONLY)) < 0)
80 return (-1); /* errno is set for us */
81

--- 22 unchanged lines hidden (view full) ---

104 (void) close(fd);
105
106 if (rc < 0) {
107 errno = err;
108 return (-1);
109 }
110
111 return (0);
112#endif
89}
113}