17532SSean.Ye@Sun.COM /*
27532SSean.Ye@Sun.COM * CDDL HEADER START
37532SSean.Ye@Sun.COM *
47532SSean.Ye@Sun.COM * The contents of this file are subject to the terms of the
57532SSean.Ye@Sun.COM * Common Development and Distribution License (the "License").
67532SSean.Ye@Sun.COM * You may not use this file except in compliance with the License.
77532SSean.Ye@Sun.COM *
87532SSean.Ye@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97532SSean.Ye@Sun.COM * or http://www.opensolaris.org/os/licensing.
107532SSean.Ye@Sun.COM * See the License for the specific language governing permissions
117532SSean.Ye@Sun.COM * and limitations under the License.
127532SSean.Ye@Sun.COM *
137532SSean.Ye@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
147532SSean.Ye@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157532SSean.Ye@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
167532SSean.Ye@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
177532SSean.Ye@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
187532SSean.Ye@Sun.COM *
197532SSean.Ye@Sun.COM * CDDL HEADER END
207532SSean.Ye@Sun.COM */
217532SSean.Ye@Sun.COM
227532SSean.Ye@Sun.COM /*
239783SAdrian.Frost@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
247532SSean.Ye@Sun.COM * Use is subject to license terms.
257532SSean.Ye@Sun.COM */
267532SSean.Ye@Sun.COM
277532SSean.Ye@Sun.COM #include <sys/types.h>
287532SSean.Ye@Sun.COM #include <sys/time.h>
297532SSean.Ye@Sun.COM #include <sys/nvpair.h>
307532SSean.Ye@Sun.COM #include <sys/cmn_err.h>
317532SSean.Ye@Sun.COM #include <sys/cred.h>
327532SSean.Ye@Sun.COM #include <sys/open.h>
337532SSean.Ye@Sun.COM #include <sys/ddi.h>
347532SSean.Ye@Sun.COM #include <sys/sunddi.h>
357532SSean.Ye@Sun.COM #include <sys/conf.h>
367532SSean.Ye@Sun.COM #include <sys/modctl.h>
377532SSean.Ye@Sun.COM #include <sys/cyclic.h>
387532SSean.Ye@Sun.COM #include <sys/errorq.h>
397532SSean.Ye@Sun.COM #include <sys/stat.h>
407532SSean.Ye@Sun.COM #include <sys/cpuvar.h>
417532SSean.Ye@Sun.COM #include <sys/mc_intel.h>
427532SSean.Ye@Sun.COM #include <sys/mc.h>
437532SSean.Ye@Sun.COM #include <sys/fm/protocol.h>
447532SSean.Ye@Sun.COM #include "nb_log.h"
457532SSean.Ye@Sun.COM #include "nb5000.h"
467532SSean.Ye@Sun.COM
477532SSean.Ye@Sun.COM char _depends_on[] = "drv/smbios";
487532SSean.Ye@Sun.COM
497532SSean.Ye@Sun.COM nvlist_t *inb_mc_nvl;
507532SSean.Ye@Sun.COM krwlock_t inb_mc_lock;
517532SSean.Ye@Sun.COM
527532SSean.Ye@Sun.COM char *inb_mc_snapshot;
537532SSean.Ye@Sun.COM uint_t nb_config_gen;
547532SSean.Ye@Sun.COM uint_t inb_mc_snapshotgen;
557532SSean.Ye@Sun.COM size_t inb_mc_snapshotsz;
567532SSean.Ye@Sun.COM static dev_info_t *inb_dip;
577532SSean.Ye@Sun.COM int nb_allow_detach = 0;
588037SAdrian.Frost@Sun.COM int nb_no_smbios;
597532SSean.Ye@Sun.COM
607532SSean.Ye@Sun.COM static uint64_t
rank_to_base(uint8_t branch,uint8_t rank,uint8_t * interleave,uint64_t * limit,uint64_t * hole_base,uint64_t * hole_size,uint8_t * wayp,uint8_t * branch_interleavep)617532SSean.Ye@Sun.COM rank_to_base(uint8_t branch, uint8_t rank, uint8_t *interleave, uint64_t *limit,
627532SSean.Ye@Sun.COM uint64_t *hole_base, uint64_t *hole_size, uint8_t *wayp,
637532SSean.Ye@Sun.COM uint8_t *branch_interleavep)
647532SSean.Ye@Sun.COM {
657532SSean.Ye@Sun.COM uint8_t i, j;
667532SSean.Ye@Sun.COM uint64_t base = 0;
677532SSean.Ye@Sun.COM uint64_t lt = 0;
687532SSean.Ye@Sun.COM uint64_t h = 0;
697532SSean.Ye@Sun.COM uint64_t hs = 0;
707532SSean.Ye@Sun.COM uint8_t il = 1;
717532SSean.Ye@Sun.COM uint8_t way = 0;
727532SSean.Ye@Sun.COM uint8_t branch_interleave = 0;
737532SSean.Ye@Sun.COM
747532SSean.Ye@Sun.COM for (i = 0; i < NB_MEM_RANK_SELECT; i++) {
757532SSean.Ye@Sun.COM for (j = 0; j < NB_RANKS_IN_SELECT; j++) {
767532SSean.Ye@Sun.COM if (nb_ranks[branch][i].rank[j] == rank) {
777532SSean.Ye@Sun.COM base = nb_ranks[branch][i].base;
787532SSean.Ye@Sun.COM lt = nb_ranks[branch][i].limit;
797532SSean.Ye@Sun.COM il = nb_ranks[branch][i].interleave;
807532SSean.Ye@Sun.COM h = nb_ranks[branch][i].hole_base;
817532SSean.Ye@Sun.COM hs = nb_ranks[branch][i].hole_size;
827532SSean.Ye@Sun.COM way = j;
837532SSean.Ye@Sun.COM branch_interleave =
847532SSean.Ye@Sun.COM nb_ranks[branch][i].branch_interleave;
857532SSean.Ye@Sun.COM i = NB_MEM_RANK_SELECT;
867532SSean.Ye@Sun.COM break;
877532SSean.Ye@Sun.COM }
887532SSean.Ye@Sun.COM }
897532SSean.Ye@Sun.COM }
907532SSean.Ye@Sun.COM if (lt == 0) {
917532SSean.Ye@Sun.COM for (i = 0; lt == 0 && i < NB_MEM_BRANCH_SELECT; i++) {
927532SSean.Ye@Sun.COM if (nb_banks[i].way[branch] &&
937532SSean.Ye@Sun.COM base >= nb_banks[i].base &&
947532SSean.Ye@Sun.COM base < nb_banks[i].base + nb_banks[i].limit) {
957532SSean.Ye@Sun.COM lt = nb_banks[i].limit;
967532SSean.Ye@Sun.COM break;
977532SSean.Ye@Sun.COM }
987532SSean.Ye@Sun.COM }
997532SSean.Ye@Sun.COM }
1007532SSean.Ye@Sun.COM *interleave = il;
1017532SSean.Ye@Sun.COM *limit = lt;
1027532SSean.Ye@Sun.COM *hole_base = h;
1037532SSean.Ye@Sun.COM *hole_size = hs;
1047532SSean.Ye@Sun.COM *wayp = way;
1057532SSean.Ye@Sun.COM *branch_interleavep = branch_interleave;
1067532SSean.Ye@Sun.COM return (base);
1077532SSean.Ye@Sun.COM }
1087532SSean.Ye@Sun.COM
109*10049SVuong.Nguyen@Sun.COM /*ARGSUSED*/
1107532SSean.Ye@Sun.COM void
inb_rank(nvlist_t * newdimm,nb_dimm_t * nb_dimm,uint8_t channel,uint32_t dimm)1117532SSean.Ye@Sun.COM inb_rank(nvlist_t *newdimm, nb_dimm_t *nb_dimm, uint8_t channel, uint32_t dimm)
1127532SSean.Ye@Sun.COM {
1137532SSean.Ye@Sun.COM nvlist_t **newrank;
1147532SSean.Ye@Sun.COM int i;
1157532SSean.Ye@Sun.COM
1167532SSean.Ye@Sun.COM newrank = kmem_zalloc(sizeof (nvlist_t *) * nb_dimm->nranks, KM_SLEEP);
1177532SSean.Ye@Sun.COM for (i = 0; i < nb_dimm->nranks; i++) {
1187532SSean.Ye@Sun.COM uint64_t dimm_base;
1197532SSean.Ye@Sun.COM uint64_t limit;
1207532SSean.Ye@Sun.COM uint8_t interleave;
1217532SSean.Ye@Sun.COM uint8_t way;
1227532SSean.Ye@Sun.COM uint8_t branch_interleave;
1237532SSean.Ye@Sun.COM uint64_t hole_base;
1247532SSean.Ye@Sun.COM uint64_t hole_size;
1257532SSean.Ye@Sun.COM
126*10049SVuong.Nguyen@Sun.COM dimm_base = rank_to_base(channel/nb_channels_per_branch,
127*10049SVuong.Nguyen@Sun.COM nb_dimm->start_rank + i, &interleave,
1287532SSean.Ye@Sun.COM &limit, &hole_base, &hole_size, &way, &branch_interleave);
1297532SSean.Ye@Sun.COM (void) nvlist_alloc(&newrank[i], NV_UNIQUE_NAME, KM_SLEEP);
1307532SSean.Ye@Sun.COM
1317532SSean.Ye@Sun.COM (void) nvlist_add_uint64(newrank[i], "dimm-rank-base",
1327532SSean.Ye@Sun.COM dimm_base);
1337532SSean.Ye@Sun.COM if (hole_size) {
1347532SSean.Ye@Sun.COM (void) nvlist_add_uint64(newrank[i], "dimm-hole",
1357532SSean.Ye@Sun.COM hole_base);
1367532SSean.Ye@Sun.COM (void) nvlist_add_uint64(newrank[i], "dimm-hole-size",
1377532SSean.Ye@Sun.COM hole_size);
1387532SSean.Ye@Sun.COM }
1397532SSean.Ye@Sun.COM (void) nvlist_add_uint64(newrank[i], "dimm-rank-limit",
1407532SSean.Ye@Sun.COM limit);
1417532SSean.Ye@Sun.COM if (interleave > 1) {
1427532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newrank[i],
1437532SSean.Ye@Sun.COM "dimm-rank-interleave", (uint32_t)interleave);
1447532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newrank[i],
1457532SSean.Ye@Sun.COM "dimm-rank-interleave-way", (uint32_t)way);
1467532SSean.Ye@Sun.COM if (branch_interleave) {
1477532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newrank[i],
1487532SSean.Ye@Sun.COM "dimm-rank-interleave-branch", (uint32_t)1);
1497532SSean.Ye@Sun.COM }
1507532SSean.Ye@Sun.COM }
1517532SSean.Ye@Sun.COM }
1527532SSean.Ye@Sun.COM (void) nvlist_add_nvlist_array(newdimm, MCINTEL_NVLIST_RANKS, newrank,
1537532SSean.Ye@Sun.COM nb_dimm->nranks);
1547532SSean.Ye@Sun.COM for (i = 0; i < nb_dimm->nranks; i++)
1557532SSean.Ye@Sun.COM nvlist_free(newrank[i]);
1567532SSean.Ye@Sun.COM kmem_free(newrank, sizeof (nvlist_t *) * nb_dimm->nranks);
1577532SSean.Ye@Sun.COM }
1587532SSean.Ye@Sun.COM
1597532SSean.Ye@Sun.COM nvlist_t *
inb_dimm(nb_dimm_t * nb_dimm,uint8_t channel,uint32_t dimm)1607532SSean.Ye@Sun.COM inb_dimm(nb_dimm_t *nb_dimm, uint8_t channel, uint32_t dimm)
1617532SSean.Ye@Sun.COM {
1627532SSean.Ye@Sun.COM nvlist_t *newdimm;
1637532SSean.Ye@Sun.COM uint8_t t;
1647532SSean.Ye@Sun.COM char sbuf[65];
1657532SSean.Ye@Sun.COM
1667532SSean.Ye@Sun.COM (void) nvlist_alloc(&newdimm, NV_UNIQUE_NAME, KM_SLEEP);
1677532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newdimm, "dimm-number", dimm);
1687532SSean.Ye@Sun.COM
1697532SSean.Ye@Sun.COM if (nb_dimm->dimm_size >= 1024*1024*1024) {
1707532SSean.Ye@Sun.COM (void) snprintf(sbuf, sizeof (sbuf), "%dG",
1717532SSean.Ye@Sun.COM (int)(nb_dimm->dimm_size / (1024*1024*1024)));
1727532SSean.Ye@Sun.COM } else {
1737532SSean.Ye@Sun.COM (void) snprintf(sbuf, sizeof (sbuf), "%dM",
1747532SSean.Ye@Sun.COM (int)(nb_dimm->dimm_size / (1024*1024)));
1757532SSean.Ye@Sun.COM }
1767532SSean.Ye@Sun.COM (void) nvlist_add_string(newdimm, "dimm-size", sbuf);
1777532SSean.Ye@Sun.COM (void) nvlist_add_uint64(newdimm, "size", nb_dimm->dimm_size);
1787532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newdimm, "nbanks", (uint32_t)nb_dimm->nbanks);
1797532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newdimm, "ncolumn",
1807532SSean.Ye@Sun.COM (uint32_t)nb_dimm->ncolumn);
1817532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newdimm, "nrow", (uint32_t)nb_dimm->nrow);
1827532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newdimm, "width", (uint32_t)nb_dimm->width);
183*10049SVuong.Nguyen@Sun.COM (void) nvlist_add_int32(newdimm, MCINTEL_NVLIST_1ST_RANK,
184*10049SVuong.Nguyen@Sun.COM (int32_t)nb_dimm->start_rank);
1857532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newdimm, "ranks", (uint32_t)nb_dimm->nranks);
1867532SSean.Ye@Sun.COM inb_rank(newdimm, nb_dimm, channel, dimm);
1877532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newdimm, "manufacture-id",
1887532SSean.Ye@Sun.COM (uint32_t)nb_dimm->manufacture_id);
1897532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newdimm, "manufacture-location",
1907532SSean.Ye@Sun.COM (uint32_t)nb_dimm->manufacture_location);
1917532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newdimm, "manufacture-week",
1927532SSean.Ye@Sun.COM (uint32_t)nb_dimm->manufacture_week);
1937532SSean.Ye@Sun.COM (void) nvlist_add_uint32(newdimm, "manufacture-year",
1947532SSean.Ye@Sun.COM (uint32_t)nb_dimm->manufacture_year + 2000);
1957532SSean.Ye@Sun.COM /* create Sun Serial number from SPD data */
1967532SSean.Ye@Sun.COM (void) snprintf(sbuf, sizeof (sbuf), "%04x%02x%02x%02x%08x",
1977532SSean.Ye@Sun.COM (uint32_t)nb_dimm->manufacture_id & 0x7fff,
1987532SSean.Ye@Sun.COM (uint32_t)nb_dimm->manufacture_location,
1997532SSean.Ye@Sun.COM (uint32_t)nb_dimm->manufacture_year,
2007532SSean.Ye@Sun.COM (uint32_t)nb_dimm->manufacture_week,
2017532SSean.Ye@Sun.COM nb_dimm->serial_number);
2027532SSean.Ye@Sun.COM (void) nvlist_add_string(newdimm, FM_FMRI_HC_SERIAL_ID, sbuf);
2037532SSean.Ye@Sun.COM if (nb_dimm->part_number && nb_dimm->part_number[0]) {
2047532SSean.Ye@Sun.COM t = sizeof (nb_dimm->part_number);
2057532SSean.Ye@Sun.COM (void) strncpy(sbuf, nb_dimm->part_number, t);
2067532SSean.Ye@Sun.COM sbuf[t] = 0;
2077532SSean.Ye@Sun.COM (void) nvlist_add_string(newdimm, FM_FMRI_HC_PART, sbuf);
2087532SSean.Ye@Sun.COM }
2097532SSean.Ye@Sun.COM if (nb_dimm->revision && nb_dimm->revision[0]) {
2107532SSean.Ye@Sun.COM t = sizeof (nb_dimm->revision);
2117532SSean.Ye@Sun.COM (void) strncpy(sbuf, nb_dimm->revision, t);
2127532SSean.Ye@Sun.COM sbuf[t] = 0;
2137532SSean.Ye@Sun.COM (void) nvlist_add_string(newdimm, FM_FMRI_HC_REVISION, sbuf);
2147532SSean.Ye@Sun.COM }
2157532SSean.Ye@Sun.COM t = sizeof (nb_dimm->label);
2167532SSean.Ye@Sun.COM (void) strncpy(sbuf, nb_dimm->label, t);
2177532SSean.Ye@Sun.COM sbuf[t] = 0;
2187532SSean.Ye@Sun.COM (void) nvlist_add_string(newdimm, FM_FAULT_FRU_LABEL, sbuf);
2197532SSean.Ye@Sun.COM return (newdimm);
2207532SSean.Ye@Sun.COM }
2217532SSean.Ye@Sun.COM
2227532SSean.Ye@Sun.COM static void
inb_dimmlist(nvlist_t * nvl)2237532SSean.Ye@Sun.COM inb_dimmlist(nvlist_t *nvl)
2247532SSean.Ye@Sun.COM {
2257532SSean.Ye@Sun.COM nvlist_t **dimmlist;
2267532SSean.Ye@Sun.COM nvlist_t **newchannel;
227*10049SVuong.Nguyen@Sun.COM int nchannels = nb_number_memory_controllers * nb_channels_per_branch;
2287532SSean.Ye@Sun.COM int nd;
2297532SSean.Ye@Sun.COM uint8_t i, j;
2307532SSean.Ye@Sun.COM nb_dimm_t **dimmpp;
2317532SSean.Ye@Sun.COM nb_dimm_t *dimmp;
2327532SSean.Ye@Sun.COM
2337532SSean.Ye@Sun.COM dimmlist = kmem_zalloc(sizeof (nvlist_t *) * nb_dimms_per_channel,
2347532SSean.Ye@Sun.COM KM_SLEEP);
2357532SSean.Ye@Sun.COM newchannel = kmem_zalloc(sizeof (nvlist_t *) * nchannels, KM_SLEEP);
2367532SSean.Ye@Sun.COM dimmpp = nb_dimms;
2377532SSean.Ye@Sun.COM for (i = 0; i < nchannels; i++) {
2387532SSean.Ye@Sun.COM (void) nvlist_alloc(&newchannel[i], NV_UNIQUE_NAME, KM_SLEEP);
2397532SSean.Ye@Sun.COM nd = 0;
2407532SSean.Ye@Sun.COM for (j = 0; j < nb_dimms_per_channel; j++) {
2417532SSean.Ye@Sun.COM dimmp = *dimmpp;
2427532SSean.Ye@Sun.COM if (dimmp != NULL) {
2437532SSean.Ye@Sun.COM dimmlist[nd] = inb_dimm(dimmp, i, (uint32_t)j);
2447532SSean.Ye@Sun.COM nd++;
2457532SSean.Ye@Sun.COM }
2467532SSean.Ye@Sun.COM dimmpp++;
2477532SSean.Ye@Sun.COM }
2487532SSean.Ye@Sun.COM if (nd) {
2497532SSean.Ye@Sun.COM (void) nvlist_add_nvlist_array(newchannel[i],
2507532SSean.Ye@Sun.COM "memory-dimms", dimmlist, nd);
2517532SSean.Ye@Sun.COM for (j = 0; j < nd; j++)
2527532SSean.Ye@Sun.COM nvlist_free(dimmlist[j]);
2537532SSean.Ye@Sun.COM }
2547532SSean.Ye@Sun.COM }
2557532SSean.Ye@Sun.COM (void) nvlist_add_nvlist_array(nvl, MCINTEL_NVLIST_MC, newchannel,
2567532SSean.Ye@Sun.COM nchannels);
2577532SSean.Ye@Sun.COM for (i = 0; i < nchannels; i++)
2587532SSean.Ye@Sun.COM nvlist_free(newchannel[i]);
2597532SSean.Ye@Sun.COM kmem_free(dimmlist, sizeof (nvlist_t *) * nb_dimms_per_channel);
2607532SSean.Ye@Sun.COM kmem_free(newchannel, sizeof (nvlist_t *) * nchannels);
2617532SSean.Ye@Sun.COM }
2627532SSean.Ye@Sun.COM
2637532SSean.Ye@Sun.COM static char *
inb_mc_name()2647532SSean.Ye@Sun.COM inb_mc_name()
2657532SSean.Ye@Sun.COM {
2667532SSean.Ye@Sun.COM char *mc;
2677532SSean.Ye@Sun.COM
2687532SSean.Ye@Sun.COM switch (nb_chipset) {
2697532SSean.Ye@Sun.COM case INTEL_NB_7300:
2707532SSean.Ye@Sun.COM mc = "Intel 7300";
2717532SSean.Ye@Sun.COM break;
2727532SSean.Ye@Sun.COM case INTEL_NB_5400:
2737532SSean.Ye@Sun.COM mc = "Intel 5400";
2747532SSean.Ye@Sun.COM break;
2757532SSean.Ye@Sun.COM case INTEL_NB_5400A:
2767532SSean.Ye@Sun.COM mc = "Intel 5400A";
2777532SSean.Ye@Sun.COM break;
2787532SSean.Ye@Sun.COM case INTEL_NB_5400B:
2797532SSean.Ye@Sun.COM mc = "Intel 5400B";
2807532SSean.Ye@Sun.COM break;
281*10049SVuong.Nguyen@Sun.COM case INTEL_NB_5100:
282*10049SVuong.Nguyen@Sun.COM mc = "Intel 5100";
283*10049SVuong.Nguyen@Sun.COM break;
2847532SSean.Ye@Sun.COM case INTEL_NB_5000P:
2857532SSean.Ye@Sun.COM mc = "Intel 5000P";
2867532SSean.Ye@Sun.COM break;
2877532SSean.Ye@Sun.COM case INTEL_NB_5000V:
2887532SSean.Ye@Sun.COM mc = "Intel 5000V";
2897532SSean.Ye@Sun.COM break;
2907532SSean.Ye@Sun.COM case INTEL_NB_5000X:
2917532SSean.Ye@Sun.COM mc = "Intel 5000X";
2927532SSean.Ye@Sun.COM break;
2937532SSean.Ye@Sun.COM case INTEL_NB_5000Z:
2947532SSean.Ye@Sun.COM mc = "Intel 5000Z";
2957532SSean.Ye@Sun.COM break;
2967532SSean.Ye@Sun.COM default:
2977532SSean.Ye@Sun.COM mc = "Intel 5000";
2987532SSean.Ye@Sun.COM break;
2997532SSean.Ye@Sun.COM }
3007532SSean.Ye@Sun.COM return (mc);
3017532SSean.Ye@Sun.COM }
3027532SSean.Ye@Sun.COM
3037532SSean.Ye@Sun.COM static void
inb_create_nvl()3047532SSean.Ye@Sun.COM inb_create_nvl()
3057532SSean.Ye@Sun.COM {
3067532SSean.Ye@Sun.COM nvlist_t *nvl;
3077532SSean.Ye@Sun.COM
3087532SSean.Ye@Sun.COM (void) nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_SLEEP);
3097532SSean.Ye@Sun.COM (void) nvlist_add_uint8(nvl, MCINTEL_NVLIST_VERSTR,
3107532SSean.Ye@Sun.COM MCINTEL_NVLIST_VERS);
3117532SSean.Ye@Sun.COM (void) nvlist_add_string(nvl, "memory-controller", inb_mc_name());
312*10049SVuong.Nguyen@Sun.COM if (nb_chipset == INTEL_NB_5100)
313*10049SVuong.Nguyen@Sun.COM (void) nvlist_add_uint8(nvl, MCINTEL_NVLIST_NMEM,
314*10049SVuong.Nguyen@Sun.COM (uint8_t)nb_number_memory_controllers);
3157532SSean.Ye@Sun.COM inb_dimmlist(nvl);
3167532SSean.Ye@Sun.COM
3177532SSean.Ye@Sun.COM if (inb_mc_nvl)
3187532SSean.Ye@Sun.COM nvlist_free(inb_mc_nvl);
3197532SSean.Ye@Sun.COM inb_mc_nvl = nvl;
3207532SSean.Ye@Sun.COM }
3217532SSean.Ye@Sun.COM
3227532SSean.Ye@Sun.COM static void
inb_mc_snapshot_destroy()3237532SSean.Ye@Sun.COM inb_mc_snapshot_destroy()
3247532SSean.Ye@Sun.COM {
3257532SSean.Ye@Sun.COM ASSERT(RW_LOCK_HELD(&inb_mc_lock));
3267532SSean.Ye@Sun.COM
3277532SSean.Ye@Sun.COM if (inb_mc_snapshot == NULL)
3287532SSean.Ye@Sun.COM return;
3297532SSean.Ye@Sun.COM
3307532SSean.Ye@Sun.COM kmem_free(inb_mc_snapshot, inb_mc_snapshotsz);
3317532SSean.Ye@Sun.COM inb_mc_snapshot = NULL;
3327532SSean.Ye@Sun.COM inb_mc_snapshotsz = 0;
3337532SSean.Ye@Sun.COM inb_mc_snapshotgen++;
3347532SSean.Ye@Sun.COM }
3357532SSean.Ye@Sun.COM
3367532SSean.Ye@Sun.COM static int
inb_mc_snapshot_update()3377532SSean.Ye@Sun.COM inb_mc_snapshot_update()
3387532SSean.Ye@Sun.COM {
3397532SSean.Ye@Sun.COM ASSERT(RW_LOCK_HELD(&inb_mc_lock));
3407532SSean.Ye@Sun.COM
3417532SSean.Ye@Sun.COM if (inb_mc_snapshot != NULL)
3427532SSean.Ye@Sun.COM return (0);
3437532SSean.Ye@Sun.COM
3447532SSean.Ye@Sun.COM if (nvlist_pack(inb_mc_nvl, &inb_mc_snapshot, &inb_mc_snapshotsz,
3457532SSean.Ye@Sun.COM NV_ENCODE_XDR, KM_SLEEP) != 0)
3467532SSean.Ye@Sun.COM return (-1);
3477532SSean.Ye@Sun.COM
3487532SSean.Ye@Sun.COM return (0);
3497532SSean.Ye@Sun.COM }
3507532SSean.Ye@Sun.COM
3517532SSean.Ye@Sun.COM /*ARGSUSED*/
3527532SSean.Ye@Sun.COM static int
inb_mc_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)3537532SSean.Ye@Sun.COM inb_mc_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
3547532SSean.Ye@Sun.COM int *rvalp)
3557532SSean.Ye@Sun.COM {
3567532SSean.Ye@Sun.COM int rc = 0;
3577532SSean.Ye@Sun.COM mc_snapshot_info_t mcs;
3587532SSean.Ye@Sun.COM
3597532SSean.Ye@Sun.COM if (cmd != MC_IOC_SNAPSHOT_INFO && cmd != MC_IOC_SNAPSHOT)
3607532SSean.Ye@Sun.COM return (EINVAL);
3617532SSean.Ye@Sun.COM
3627532SSean.Ye@Sun.COM rw_enter(&inb_mc_lock, RW_READER);
3637532SSean.Ye@Sun.COM if (inb_mc_nvl == NULL || inb_mc_snapshotgen != nb_config_gen) {
3647532SSean.Ye@Sun.COM if (!rw_tryupgrade(&inb_mc_lock)) {
3657532SSean.Ye@Sun.COM rw_exit(&inb_mc_lock);
3667532SSean.Ye@Sun.COM return (EAGAIN);
3677532SSean.Ye@Sun.COM }
3687532SSean.Ye@Sun.COM if (inb_mc_nvl)
3697532SSean.Ye@Sun.COM inb_mc_snapshot_destroy();
3707532SSean.Ye@Sun.COM inb_create_nvl();
3717532SSean.Ye@Sun.COM nb_config_gen = inb_mc_snapshotgen;
3727532SSean.Ye@Sun.COM (void) inb_mc_snapshot_update();
3737532SSean.Ye@Sun.COM }
3747532SSean.Ye@Sun.COM switch (cmd) {
3757532SSean.Ye@Sun.COM case MC_IOC_SNAPSHOT_INFO:
3767532SSean.Ye@Sun.COM mcs.mcs_size = (uint32_t)inb_mc_snapshotsz;
3777532SSean.Ye@Sun.COM mcs.mcs_gen = inb_mc_snapshotgen;
3787532SSean.Ye@Sun.COM
3797532SSean.Ye@Sun.COM if (ddi_copyout(&mcs, (void *)arg, sizeof (mc_snapshot_info_t),
3807532SSean.Ye@Sun.COM mode) < 0)
3817532SSean.Ye@Sun.COM rc = EFAULT;
3827532SSean.Ye@Sun.COM break;
3837532SSean.Ye@Sun.COM case MC_IOC_SNAPSHOT:
3847532SSean.Ye@Sun.COM if (ddi_copyout(inb_mc_snapshot, (void *)arg, inb_mc_snapshotsz,
3857532SSean.Ye@Sun.COM mode) < 0)
3867532SSean.Ye@Sun.COM rc = EFAULT;
3877532SSean.Ye@Sun.COM break;
3887532SSean.Ye@Sun.COM }
3897532SSean.Ye@Sun.COM rw_exit(&inb_mc_lock);
3907532SSean.Ye@Sun.COM return (rc);
3917532SSean.Ye@Sun.COM }
3927532SSean.Ye@Sun.COM
3937532SSean.Ye@Sun.COM /*ARGSUSED*/
3947532SSean.Ye@Sun.COM static int
inb_mc_getinfo(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)3957532SSean.Ye@Sun.COM inb_mc_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
3967532SSean.Ye@Sun.COM void **result)
3977532SSean.Ye@Sun.COM {
3987532SSean.Ye@Sun.COM if ((infocmd != DDI_INFO_DEVT2DEVINFO &&
3997532SSean.Ye@Sun.COM infocmd != DDI_INFO_DEVT2INSTANCE) || inb_dip == NULL) {
4007532SSean.Ye@Sun.COM *result = NULL;
4017532SSean.Ye@Sun.COM return (DDI_FAILURE);
4027532SSean.Ye@Sun.COM }
4037532SSean.Ye@Sun.COM if (infocmd == DDI_INFO_DEVT2DEVINFO)
4047532SSean.Ye@Sun.COM *result = inb_dip;
4057532SSean.Ye@Sun.COM else
4067532SSean.Ye@Sun.COM *result = (void *)(uintptr_t)ddi_get_instance(inb_dip);
4077532SSean.Ye@Sun.COM return (0);
4087532SSean.Ye@Sun.COM }
4097532SSean.Ye@Sun.COM
4107532SSean.Ye@Sun.COM static int
inb_mc_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)4117532SSean.Ye@Sun.COM inb_mc_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
4127532SSean.Ye@Sun.COM {
4137532SSean.Ye@Sun.COM if (cmd == DDI_RESUME) {
4147532SSean.Ye@Sun.COM nb_dev_reinit();
4157532SSean.Ye@Sun.COM return (DDI_SUCCESS);
4167532SSean.Ye@Sun.COM }
4177532SSean.Ye@Sun.COM if (cmd != DDI_ATTACH)
4187532SSean.Ye@Sun.COM return (DDI_FAILURE);
4197532SSean.Ye@Sun.COM if (inb_dip == NULL) {
4207532SSean.Ye@Sun.COM inb_dip = dip;
4218037SAdrian.Frost@Sun.COM nb_no_smbios = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
4228037SAdrian.Frost@Sun.COM DDI_PROP_DONTPASS, "no-smbios", 0);
4237532SSean.Ye@Sun.COM nb_pci_cfg_setup(dip);
4249783SAdrian.Frost@Sun.COM (void) ddi_prop_update_string(DDI_DEV_T_NONE, dip, "model",
4259783SAdrian.Frost@Sun.COM inb_mc_name());
4267532SSean.Ye@Sun.COM if (nb_dev_init()) {
4277532SSean.Ye@Sun.COM nb_pci_cfg_free();
4287532SSean.Ye@Sun.COM inb_dip = NULL;
4297532SSean.Ye@Sun.COM return (DDI_FAILURE);
4307532SSean.Ye@Sun.COM }
4317532SSean.Ye@Sun.COM if (ddi_create_minor_node(dip, "mc-intel", S_IFCHR, 0,
4327532SSean.Ye@Sun.COM "ddi_mem_ctrl", 0) != DDI_SUCCESS) {
4337532SSean.Ye@Sun.COM cmn_err(CE_WARN, "failed to create minor node"
4347532SSean.Ye@Sun.COM " for memory controller\n");
4357532SSean.Ye@Sun.COM }
4367532SSean.Ye@Sun.COM cmi_hdl_walk(inb_mc_register, NULL, NULL, NULL);
4377532SSean.Ye@Sun.COM }
4387532SSean.Ye@Sun.COM
4397532SSean.Ye@Sun.COM return (DDI_SUCCESS);
4407532SSean.Ye@Sun.COM }
4417532SSean.Ye@Sun.COM
4427532SSean.Ye@Sun.COM /*ARGSUSED*/
4437532SSean.Ye@Sun.COM static int
inb_mc_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)4447532SSean.Ye@Sun.COM inb_mc_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
4457532SSean.Ye@Sun.COM {
4467532SSean.Ye@Sun.COM if (nb_allow_detach && cmd == DDI_DETACH && dip == inb_dip) {
4477532SSean.Ye@Sun.COM rw_enter(&inb_mc_lock, RW_WRITER);
4487532SSean.Ye@Sun.COM inb_mc_snapshot_destroy();
4497532SSean.Ye@Sun.COM rw_exit(&inb_mc_lock);
4507532SSean.Ye@Sun.COM inb_dip = NULL;
4517532SSean.Ye@Sun.COM return (DDI_SUCCESS);
4527532SSean.Ye@Sun.COM } else if (cmd == DDI_SUSPEND || cmd == DDI_PM_SUSPEND) {
4537532SSean.Ye@Sun.COM return (DDI_SUCCESS);
4547532SSean.Ye@Sun.COM } else {
4557532SSean.Ye@Sun.COM return (DDI_FAILURE);
4567532SSean.Ye@Sun.COM }
4577532SSean.Ye@Sun.COM }
4587532SSean.Ye@Sun.COM
4597532SSean.Ye@Sun.COM /*ARGSUSED*/
4607532SSean.Ye@Sun.COM static int
inb_mc_open(dev_t * devp,int flag,int otyp,cred_t * credp)4617532SSean.Ye@Sun.COM inb_mc_open(dev_t *devp, int flag, int otyp, cred_t *credp)
4627532SSean.Ye@Sun.COM {
4637532SSean.Ye@Sun.COM if (otyp != OTYP_CHR)
4647532SSean.Ye@Sun.COM return (EINVAL);
4657532SSean.Ye@Sun.COM
4667532SSean.Ye@Sun.COM rw_enter(&inb_mc_lock, RW_READER);
4677532SSean.Ye@Sun.COM if (getminor(*devp) >= 1) {
4687532SSean.Ye@Sun.COM rw_exit(&inb_mc_lock);
4697532SSean.Ye@Sun.COM return (EINVAL);
4707532SSean.Ye@Sun.COM }
4717532SSean.Ye@Sun.COM rw_exit(&inb_mc_lock);
4727532SSean.Ye@Sun.COM
4737532SSean.Ye@Sun.COM return (0);
4747532SSean.Ye@Sun.COM }
4757532SSean.Ye@Sun.COM
4767532SSean.Ye@Sun.COM /*ARGSUSED*/
4777532SSean.Ye@Sun.COM static int
inb_mc_close(dev_t dev,int flag,int otyp,cred_t * credp)4787532SSean.Ye@Sun.COM inb_mc_close(dev_t dev, int flag, int otyp, cred_t *credp)
4797532SSean.Ye@Sun.COM {
4807532SSean.Ye@Sun.COM return (0);
4817532SSean.Ye@Sun.COM }
4827532SSean.Ye@Sun.COM
4837532SSean.Ye@Sun.COM
4847532SSean.Ye@Sun.COM static struct cb_ops inb_mc_cb_ops = {
4857532SSean.Ye@Sun.COM inb_mc_open,
4867532SSean.Ye@Sun.COM inb_mc_close,
4877532SSean.Ye@Sun.COM nodev, /* not a block driver */
4887532SSean.Ye@Sun.COM nodev, /* no print routine */
4897532SSean.Ye@Sun.COM nodev, /* no dump routine */
4907532SSean.Ye@Sun.COM nodev, /* no read routine */
4917532SSean.Ye@Sun.COM nodev, /* no write routine */
4927532SSean.Ye@Sun.COM inb_mc_ioctl,
4937532SSean.Ye@Sun.COM nodev, /* no devmap routine */
4947532SSean.Ye@Sun.COM nodev, /* no mmap routine */
4957532SSean.Ye@Sun.COM nodev, /* no segmap routine */
4967532SSean.Ye@Sun.COM nochpoll, /* no chpoll routine */
4977532SSean.Ye@Sun.COM ddi_prop_op,
4987532SSean.Ye@Sun.COM 0, /* not a STREAMS driver */
4997532SSean.Ye@Sun.COM D_NEW | D_MP, /* safe for multi-thread/multi-processor */
5007532SSean.Ye@Sun.COM };
5017532SSean.Ye@Sun.COM
5027532SSean.Ye@Sun.COM static struct dev_ops inb_mc_ops = {
5037532SSean.Ye@Sun.COM DEVO_REV, /* devo_rev */
5047532SSean.Ye@Sun.COM 0, /* devo_refcnt */
5057532SSean.Ye@Sun.COM inb_mc_getinfo, /* devo_getinfo */
5067532SSean.Ye@Sun.COM nulldev, /* devo_identify */
5077532SSean.Ye@Sun.COM nulldev, /* devo_probe */
5087532SSean.Ye@Sun.COM inb_mc_attach, /* devo_attach */
5097532SSean.Ye@Sun.COM inb_mc_detach, /* devo_detach */
5107532SSean.Ye@Sun.COM nodev, /* devo_reset */
5117532SSean.Ye@Sun.COM &inb_mc_cb_ops, /* devo_cb_ops */
5127532SSean.Ye@Sun.COM NULL, /* devo_bus_ops */
5137656SSherry.Moore@Sun.COM NULL, /* devo_power */
5147656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* devo_quiesce */
5157532SSean.Ye@Sun.COM };
5167532SSean.Ye@Sun.COM
5177532SSean.Ye@Sun.COM static struct modldrv modldrv = {
5187532SSean.Ye@Sun.COM &mod_driverops,
5197532SSean.Ye@Sun.COM "Intel 5000 Memory Controller Hub Module",
5207532SSean.Ye@Sun.COM &inb_mc_ops
5217532SSean.Ye@Sun.COM };
5227532SSean.Ye@Sun.COM
5237532SSean.Ye@Sun.COM static struct modlinkage modlinkage = {
5247532SSean.Ye@Sun.COM MODREV_1,
5257532SSean.Ye@Sun.COM (void *)&modldrv,
5267532SSean.Ye@Sun.COM NULL
5277532SSean.Ye@Sun.COM };
5287532SSean.Ye@Sun.COM
5297532SSean.Ye@Sun.COM int
_init(void)5307532SSean.Ye@Sun.COM _init(void)
5317532SSean.Ye@Sun.COM {
5327532SSean.Ye@Sun.COM int err;
5337532SSean.Ye@Sun.COM
5347532SSean.Ye@Sun.COM err = nb_init();
5357532SSean.Ye@Sun.COM if (err == 0 && (err = mod_install(&modlinkage)) == 0)
5367532SSean.Ye@Sun.COM rw_init(&inb_mc_lock, NULL, RW_DRIVER, NULL);
5377532SSean.Ye@Sun.COM
5387532SSean.Ye@Sun.COM return (err);
5397532SSean.Ye@Sun.COM }
5407532SSean.Ye@Sun.COM
5417532SSean.Ye@Sun.COM int
_info(struct modinfo * modinfop)5427532SSean.Ye@Sun.COM _info(struct modinfo *modinfop)
5437532SSean.Ye@Sun.COM {
5447532SSean.Ye@Sun.COM return (mod_info(&modlinkage, modinfop));
5457532SSean.Ye@Sun.COM }
5467532SSean.Ye@Sun.COM
5477532SSean.Ye@Sun.COM int
_fini(void)5487532SSean.Ye@Sun.COM _fini(void)
5497532SSean.Ye@Sun.COM {
5507532SSean.Ye@Sun.COM int err;
5517532SSean.Ye@Sun.COM
5527532SSean.Ye@Sun.COM if ((err = mod_remove(&modlinkage)) == 0) {
5537532SSean.Ye@Sun.COM nb_unload();
5547532SSean.Ye@Sun.COM rw_destroy(&inb_mc_lock);
5557532SSean.Ye@Sun.COM }
5567532SSean.Ye@Sun.COM
5577532SSean.Ye@Sun.COM return (err);
5587532SSean.Ye@Sun.COM }
559