#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sebuf.c,v 1.22 2026/01/05 10:44:52 andvar Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/proc.h>
#include <sys/tty.h>
#include <uvm/uvm_extern.h>
#include <machine/autoconf.h>
#include <machine/cpu.h>
#include "sereg.h"
#include "sevar.h"
struct sebuf_softc {
device_t sc_dev;
struct sebuf_regs *sc_regs;
};
static int sebuf_match(device_t, cfdata_t, void *);
static void sebuf_attach(device_t, device_t, void *);
static int sebuf_print(void *, const char *);
CFATTACH_DECL_NEW(sebuf, sizeof(struct sebuf_softc),
sebuf_match, sebuf_attach, NULL, NULL);
static int
sebuf_match(device_t parent, cfdata_t cf, void *args)
{
struct confargs *ca = args;
struct se_regs *sreg;
struct ie_regs *ereg;
int pa, x;
if (ca->ca_paddr == -1)
return 0;
pa = ca->ca_paddr;
x = bus_peek(ca->ca_bustype, pa, 2);
if (x == -1)
return 0;
pa = ca->ca_paddr + offsetof(struct sebuf_regs, se_scsi_regs);
sreg = bus_tmapin(ca->ca_bustype, pa);
sreg->se_csr = 0xFFF3;
x = peek_word((void *)(&sreg->se_csr));
bus_tmapout(sreg);
if ((x == -1) || (x & 0xFCF0)) {
#ifdef DEBUG
aprint_debug("%s: SCSI csr=0x%x\n", __func__, x);
#endif
return 0;
}
pa = ca->ca_paddr + offsetof(struct sebuf_regs, se_eth_regs);
ereg = bus_tmapin(ca->ca_bustype, pa);
ereg->ie_csr = 0x0FFF;
x = peek_word((void *)(&ereg->ie_csr));
bus_tmapout(ereg);
if ((x == -1) || (x & 0xFFF)) {
#ifdef DEBUG
printf("%s: Ether csr=0x%x\n", __func__, x);
#endif
return 0;
}
if (ca->ca_intpri == -1)
ca->ca_intpri = 2;
return 1;
}
static void
sebuf_attach(device_t parent, device_t self, void *args)
{
struct sebuf_softc *sc = device_private(self);
struct confargs *ca = args;
struct sebuf_attach_args aa;
struct sebuf_regs *regs;
sc->sc_dev = self;
aprint_normal("\n");
if (ca->ca_intpri != 2)
panic("sebuf: bad level");
regs = (struct sebuf_regs *)bus_mapin(ca->ca_bustype, ca->ca_paddr,
sizeof(struct sebuf_regs));
if (regs == NULL)
panic("%s", __func__);
sc->sc_regs = regs;
aa.ca = *ca;
aa.ca.ca_paddr = 0;
aa.name = "se";
aa.buf = ®s->se_scsi_buf[0];
aa.blen = SE_NCRBUFSIZE;
aa.regs = ®s->se_scsi_regs;
(void)config_found(self, (void *)&aa, sebuf_print, CFARGS_NONE);
aa.ca.ca_intpri++;
aa.ca.ca_intvec++;
aa.name = "ie";
aa.buf = ®s->se_eth_buf[0];
aa.blen = SE_IEBUFSIZE;
aa.regs = ®s->se_eth_regs;
(void)config_found(self, (void *)&aa, sebuf_print, CFARGS_NONE);
}
static int
sebuf_print(void *aux, const char *name)
{
if (name != NULL)
aprint_normal("%s: ", name);
return UNCONF;
}