Deleted Added
full compact
biossmap.c (179631) biossmap.c (191111)
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/boot/i386/libi386/biossmap.c 179631 2008-06-07 03:07:32Z jhb $");
28__FBSDID("$FreeBSD: head/sys/boot/i386/libi386/biossmap.c 191111 2009-04-15 17:31:22Z jkim $");
29
30/*
31 * Obtain memory configuration information from the BIOS
32 */
33#include <stand.h>
34#include <sys/param.h>
35#include <sys/linker.h>
29
30/*
31 * Obtain memory configuration information from the BIOS
32 */
33#include <stand.h>
34#include <sys/param.h>
35#include <sys/linker.h>
36#include <sys/queue.h>
37#include <sys/stddef.h>
36#include <machine/metadata.h>
38#include <machine/metadata.h>
39#include <machine/psl.h>
37#include <machine/pc/bios.h>
38#include "bootstrap.h"
39#include "libi386.h"
40#include "btxv86.h"
41
40#include <machine/pc/bios.h>
41#include "bootstrap.h"
42#include "libi386.h"
43#include "btxv86.h"
44
42static struct {
43 struct bios_smap _smap_entry;
44 char pad[8]; /* Bad BIOS writer, no cookie! */
45} smap;
45#define V86_CY(x) ((x) & PSL_C)
46
46
47static struct bios_smap *smapbase;
48static int smaplen;
47struct smap_buf {
48 struct bios_smap smap;
49 uint32_t xattr; /* Extended attribute from ACPI 3.0 */
50 STAILQ_ENTRY(smap_buf) bufs;
51};
49
52
53#define SMAP_BUFSIZE offsetof(struct smap_buf, bufs)
54
55static struct bios_smap *smapbase;
56static uint32_t *smapattr;
57static u_int smaplen;
58
50void
51bios_getsmap(void)
52{
59void
60bios_getsmap(void)
61{
53 int n;
62 struct smap_buf buf;
63 STAILQ_HEAD(smap_head, smap_buf) head =
64 STAILQ_HEAD_INITIALIZER(head);
65 struct smap_buf *cur, *next;
66 u_int n, x;
54
67
68 STAILQ_INIT(&head);
55 n = 0;
69 n = 0;
56 smaplen = 0;
57 /* Count up segments in system memory map */
70 x = 0;
58 v86.ebx = 0;
59 do {
60 v86.ctl = V86_FLAGS;
71 v86.ebx = 0;
72 do {
73 v86.ctl = V86_FLAGS;
61 v86.addr = 0x15; /* int 0x15 function 0xe820*/
62 v86.eax = 0xe820;
63 v86.ecx = sizeof(struct bios_smap);
74 v86.addr = 0x15;
75 v86.eax = 0xe820; /* int 0x15 function 0xe820 */
76 v86.ecx = SMAP_BUFSIZE;
64 v86.edx = SMAP_SIG;
77 v86.edx = SMAP_SIG;
65 v86.es = VTOPSEG(&smap);
66 v86.edi = VTOPOFF(&smap);
78 v86.es = VTOPSEG(&buf);
79 v86.edi = VTOPOFF(&buf);
67 v86int();
80 v86int();
68 if ((v86.efl & 1) || (v86.eax != SMAP_SIG))
81 if (V86_CY(v86.efl) || v86.eax != SMAP_SIG ||
82 v86.ecx < sizeof(buf.smap) || v86.ecx > SMAP_BUFSIZE)
69 break;
83 break;
84
85 next = malloc(sizeof(*next));
86 if (next == NULL)
87 break;
88 next->smap = buf.smap;
89 if (v86.ecx == SMAP_BUFSIZE) {
90 next->xattr = buf.xattr;
91 x++;
92 }
93 STAILQ_INSERT_TAIL(&head, next, bufs);
70 n++;
71 } while (v86.ebx != 0);
94 n++;
95 } while (v86.ebx != 0);
72 if (n == 0)
73 return;
74 n += 10; /* spare room */
75 smapbase = malloc(n * sizeof(*smapbase));
96 smaplen = n;
76
97
77 /* Save system memory map */
78 v86.ebx = 0;
79 do {
80 v86.ctl = V86_FLAGS;
81 v86.addr = 0x15; /* int 0x15 function 0xe820*/
82 v86.eax = 0xe820;
83 v86.ecx = sizeof(struct bios_smap);
84 v86.edx = SMAP_SIG;
85 v86.es = VTOPSEG(&smap);
86 v86.edi = VTOPOFF(&smap);
87 v86int();
88 bcopy(&smap, &smapbase[smaplen], sizeof(struct bios_smap));
89 smaplen++;
90 if ((v86.efl & 1) || (v86.eax != SMAP_SIG))
91 break;
92 } while (v86.ebx != 0 && smaplen < n);
98 if (smaplen > 0) {
99 smapbase = malloc(smaplen * sizeof(*smapbase));
100 if (smapbase != NULL) {
101 n = 0;
102 STAILQ_FOREACH(cur, &head, bufs)
103 smapbase[n++] = cur->smap;
104 }
105 if (smaplen == x) {
106 smapattr = malloc(smaplen * sizeof(*smapattr));
107 if (smapattr != NULL) {
108 n = 0;
109 STAILQ_FOREACH(cur, &head, bufs)
110 smapattr[n++] = cur->xattr &
111 SMAP_XATTR_MASK;
112 }
113 } else
114 smapattr = NULL;
115 cur = STAILQ_FIRST(&head);
116 while (cur != NULL) {
117 next = STAILQ_NEXT(cur, bufs);
118 free(cur);
119 cur = next;
120 }
121 }
93}
94
95void
96bios_addsmapdata(struct preloaded_file *kfp)
97{
122}
123
124void
125bios_addsmapdata(struct preloaded_file *kfp)
126{
98 int len;
127 size_t size;
99
128
100 if (smapbase == 0 || smaplen == 0)
129 if (smapbase == NULL || smaplen == 0)
101 return;
130 return;
102 len = smaplen * sizeof(*smapbase);
103 file_addmetadata(kfp, MODINFOMD_SMAP, len, smapbase);
131 size = smaplen * sizeof(*smapbase);
132 file_addmetadata(kfp, MODINFOMD_SMAP, size, smapbase);
133 if (smapattr != NULL) {
134 size = smaplen * sizeof(*smapattr);
135 file_addmetadata(kfp, MODINFOMD_SMAP_XATTR, size, smapattr);
136 }
104}
105
106COMMAND_SET(smap, "smap", "show BIOS SMAP", command_smap);
107
108static int
109command_smap(int argc, char *argv[])
110{
137}
138
139COMMAND_SET(smap, "smap", "show BIOS SMAP", command_smap);
140
141static int
142command_smap(int argc, char *argv[])
143{
111 int i;
144 u_int i;
112
145
113 if (smapbase == 0 || smaplen == 0)
146 if (smapbase == NULL || smaplen == 0)
114 return (CMD_ERROR);
147 return (CMD_ERROR);
115 for (i = 0; i < smaplen; i++)
116 printf("SMAP type=%02x base=%016llx len=%016llx\n",
117 smapbase[i].type, smapbase[i].base, smapbase[i].length);
148 if (smapattr != NULL)
149 for (i = 0; i < smaplen; i++)
150 printf("SMAP type=%02x base=%016llx len=%016llx attr=%02x\n",
151 (unsigned int)smapbase[i].type,
152 (unsigned long long)smapbase[i].base,
153 (unsigned long long)smapbase[i].length,
154 (unsigned int)smapattr[i]);
155 else
156 for (i = 0; i < smaplen; i++)
157 printf("SMAP type=%02x base=%016llx len=%016llx\n",
158 (unsigned int)smapbase[i].type,
159 (unsigned long long)smapbase[i].base,
160 (unsigned long long)smapbase[i].length);
118 return (CMD_OK);
119}
161 return (CMD_OK);
162}