2 * Copyright (c) 1998 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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
26 * $FreeBSD: src/sys/boot/arc/lib/arch/alpha/rpb.c,v 1.2 1999/08/28 00:39:40 peter Exp $
27 * $DragonFly: src/sys/boot/arc/lib/arch/alpha/Attic/rpb.c,v 1.3 2003/11/10 06:08:31 dillon Exp $
31 #include <machine/rpb.h>
37 {"HWRPB"}, /* rpb_magic */
38 HWRPB_DSRDB_MINVERS, /* rpb_version */
39 sizeof(struct rpb), /* rpb_size */
40 0, /* rpb_primary_cpu_id */
41 8192, /* rpb_page_size */
42 43, /* rpb_phys_addr_size */
45 ST_EB164, /* rpb_type */
46 SV_ST_ALPHAPC164LX_533, /* rpb_variation */
47 {"0000"}, /* rpb_revision */
48 1024*4096, /* rpb_intr_freq */
49 533*1024*1024, /* rpb_cc_freq */
51 0, /* rpb_reserved_arch */
52 0, /* rpb_tbhint_off */
60 0, /* rpb_memdat_off */
61 0, /* rpb_condat_off */
63 0, /* rpb_save_term */
64 0, /* rpb_save_term_val */
65 0, /* rpb_rest_term */
66 0, /* rpb_rest_term_val */
68 0, /* rpb_restart_val */
69 0, /* rpb_reserve_os */
70 0, /* rpb_reserve_hw */
74 0, /* rpb_dsrdb_off */
75 {0}, /* rpb_rpb_tbhint */
78 #define ROUNDUP(x) (((x) + sizeof(u_int64_t) - 1) \
79 & ~(sizeof(u_int64_t) - 1))
82 checksum(void *p, size_t size)
85 u_int64_t *lp = (u_int64_t *)p;
88 printf("checksum(%p, %d)\n", p, size);
89 size = ROUNDUP(size) / sizeof(u_int64_t);
90 for (i = 0; i < size; i++)
98 MEMORY_DESCRIPTOR *desc;
100 for (desc = GetMemoryDescriptor(NULL); desc;
101 desc = GetMemoryDescriptor(desc)) {
105 return ROUNDUP(sizeof(struct mddt)
106 + (count - 1) * sizeof(struct mddt_cluster));
110 write_mddt(struct mddt *mddt, size_t size)
113 MEMORY_DESCRIPTOR *desc;
116 memset(mddt, 0, sizeof(struct mddt));
117 for (desc = GetMemoryDescriptor(NULL); desc;
118 desc = GetMemoryDescriptor(desc)) {
119 struct mddt_cluster *mc;
120 mc = &mddt->mddt_clusters[count];
121 mc->mddt_pfn = desc->BasePage;
122 mc->mddt_pg_cnt = desc->PageCount;
123 mc->mddt_pg_test = 0;
124 mc->mddt_v_bitaddr = 0;
125 mc->mddt_p_bitaddr = 0;
126 mc->mddt_bit_cksum = 0;
129 * Not sure about the FirmwareTemporary bit but my 164LX has
130 * about 60Mb marked this way.
132 if (desc->Type == MemoryFree || desc->Type == MemoryFirmwareTemporary)
133 mc->mddt_usage = MDDT_SYSTEM;
134 else if (desc->Type == MemorySpecialMemory)
135 mc->mddt_usage = MDDT_NONVOLATILE; /* ?? */
137 mc->mddt_usage = MDDT_PALCODE;
140 mddt->mddt_cluster_cnt = count;
141 mddt->mddt_cksum = checksum(mddt, size);
147 return sizeof(struct rpb) + size_mddt();
151 write_rpb(struct rpb *rpb)
153 EXTENDED_SYSTEM_INFORMATION sysinfo;
156 ReturnExtendedSystemInformation(&sysinfo);
158 memset(rpb, 0, sizeof(struct rpb));
159 rpb->rpb_phys = 0; /* XXX */
160 strcpy(rpb->rpb_magic, "HWRPB");
161 rpb->rpb_version = HWRPB_DSRDB_MINVERS;
162 rpb->rpb_size = sizeof(struct rpb);
163 rpb->rpb_primary_cpu_id = 0; /* XXX */
164 rpb->rpb_page_size = sysinfo.ProcessorPageSize;
165 rpb->rpb_phys_addr_size = sysinfo.NumberOfPhysicalAddressBits;
166 rpb->rpb_max_asn = sysinfo.MaximumAddressSpaceNumber;
167 rpb->rpb_type = ST_EB164; /* XXX */
168 rpb->rpb_variation = SV_ST_ALPHAPC164LX_533; /* XXX */
169 rpb->rpb_intr_freq = 1024*4096; /* XXX */
170 rpb->rpb_cc_freq = 533000000; /* XXX */
171 rpb->rpb_memdat_off = sizeof(struct rpb);
172 write_mddt((struct mddt *)((caddr_t) rpb + rpb->rpb_memdat_off),
174 rpb->rpb_checksum = checksum(rpb, 280); /* only sum first 280 bytes */
180 EXTENDED_SYSTEM_INFORMATION sysinfo;
183 ReturnExtendedSystemInformation(&sysinfo);
184 printf("sysinfo.ProcessorId = %x\n", sysinfo.ProcessorId);
185 printf("sysinfo.ProcessorRevision = %d\n", sysinfo.ProcessorRevision);
186 printf("sysinfo.ProcessorPageSize = %d\n", sysinfo.ProcessorPageSize);
187 printf("sysinfo.NumberOfPhysicalAddressBits = %d\n", sysinfo.NumberOfPhysicalAddressBits);
188 printf("sysinfo.MaximumAddressSpaceNumber = %d\n", sysinfo.MaximumAddressSpaceNumber);
189 printf("sysinfo.ProcessorCycleCounterPeriod = %d\n", sysinfo.ProcessorCycleCounterPeriod);
190 printf("sysinfo.SystemRevision = %d\n", sysinfo.SystemRevision);
191 printf("sysinfo.SystemSerialNumber = %s\n", sysinfo.SystemSerialNumber);
192 printf("sysinfo.FirmwareVersion = %s\n", sysinfo.FirmwareVersion);
194 rpb = malloc(size_rpb());