+/*
+ * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution is only permitted until one year after the first shipment
+ * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
+ * binary forms are permitted provided that: (1) source distributions retain
+ * this entire copyright notice and comment, and (2) distributions including
+ * binaries display the following acknowledgement: This product includes
+ * software developed by the University of California, Berkeley and its
+ * contributors'' in the documentation or other materials provided with the
+ * distribution and in all advertising materials mentioning features or use
+ * of this software. Neither the name of the University nor the names of
+ * its contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * @(#)uipc_mbuf.c 7.17 (Berkeley) 7/25/90
+ */
+
+#include "param.h"
+#include "user.h"
+#include "proc.h"
+#include "cmap.h"
+#include "malloc.h"
+#include "map.h"
+#define MBTYPES
+#include "mbuf.h"
+#include "vm.h"
+#include "kernel.h"
+#include "syslog.h"
+#include "domain.h"
+#include "protosw.h"
+#include "machine/pte.h"
+
+mbinit()
+{
+ int s;
+
+#if MCLBYTES < 4096
+#define NCL_INIT (4096/CLBYTES)
+#else
+#define NCL_INIT 1
+#endif
+ s = splimp();
+ if (m_clalloc(NCL_INIT, M_DONTWAIT) == 0)
+ goto bad;
+ splx(s);
+ return;
+bad:
+ panic("mbinit");
+}
+
+/*
+ * Allocate some number of mbuf clusters
+ * and place on cluster free list.
+ * Must be called at splimp.
+ */
+/* ARGSUSED */
+m_clalloc(ncl, canwait)
+ register int ncl;
+{
+ int npg, mbx;
+ register caddr_t p;
+ register int i;
+ static int logged;
+
+ npg = ncl * CLSIZE;
+ mbx = rmalloc(mbmap, (long)npg);
+ if (mbx == 0) {
+ if (logged == 0) {
+ logged++;
+ log(LOG_ERR, "mbuf map full\n");
+ }
+ return (0);
+ }
+ p = cltom(mbx * NBPG / MCLBYTES);
+ if (memall(&Mbmap[mbx], npg, proc, CSYS) == 0) {
+ rmfree(mbmap, (long)npg, (long)mbx);
+ return (0);
+ }
+ vmaccess(&Mbmap[mbx], p, npg);
+ ncl = ncl * CLBYTES / MCLBYTES;
+ for (i = 0; i < ncl; i++) {
+ ((union mcluster *)p)->mcl_next = mclfree;
+ mclfree = (union mcluster *)p;
+ p += MCLBYTES;
+ mbstat.m_clfree++;
+ }
+ mbstat.m_clusters += ncl;
+ return (1);
+}