Skip to content

Commit

Permalink
Handle NeXT Turbo VRAM regions properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutsui committed Feb 9, 2023
1 parent 97b50d2 commit 58a2e85
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 89 deletions.
25 changes: 25 additions & 0 deletions sys/arch/next68k/dev/intio.c
Expand Up @@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: intio.c,v 1.18 2023/02/04 14:38:09 tsutsui Exp $");
#include <sys/reboot.h>

#include <machine/autoconf.h>
#include <machine/cpu.h>

#include <next68k/dev/intiovar.h>

Expand Down Expand Up @@ -107,3 +108,27 @@ intiosearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)

return 0;
}

int
bus_space_map(bus_space_tag_t bst, bus_addr_t addr, bus_size_t size,
int flags, bus_space_handle_t *bsh)
{

if (addr >= INTIOBASE && (addr + size) < INTIOTOP) {
*bsh = IIOV(addr);
return 0;
}

return EINVAL;
}

paddr_t
bus_space_mmap(bus_space_tag_t bst, bus_addr_t addr, off_t offset, int prot,
int flags)
{

if (addr >= INTIOBASE && (addr + offset) < INTIOTOP)
return m68k_btop(addr + offset);

return -1;
}
8 changes: 4 additions & 4 deletions sys/arch/next68k/dev/intiovar.h
Expand Up @@ -47,7 +47,7 @@ struct intio_attach_args {

extern vaddr_t intiobase;
extern vaddr_t intiolimit;
extern vaddr_t monobase;
extern vaddr_t monolimit;
extern vaddr_t colorbase;
extern vaddr_t colorlimit;
extern vaddr_t fbbase;
extern vaddr_t fblimit;
extern paddr_t fbbasepa;
extern paddr_t fblimitpa;
35 changes: 7 additions & 28 deletions sys/arch/next68k/dev/nextdisplay.c
Expand Up @@ -162,15 +162,9 @@ nextdisplay_init(struct nextdisplay_config *dc, int color)

/* printf("in nextdisplay_init\n"); */

if (color) {
dc->dc_vaddr = colorbase;
dc->dc_paddr = COLORBASE;
dc->dc_size = NEXT_P_C16_VIDEOSIZE;
} else {
dc->dc_vaddr = monobase;
dc->dc_paddr = MONOBASE;
dc->dc_size = NEXT_P_VIDEOSIZE;
}
dc->dc_vaddr = fbbase;
dc->dc_paddr = fbbasepa;
dc->dc_size = color ? NEXT_P_C16_VIDEOSIZE : NEXT_P_VIDEOSIZE;

dc->dc_wid = 1120;
dc->dc_ht = 832;
Expand All @@ -182,8 +176,8 @@ nextdisplay_init(struct nextdisplay_config *dc, int color)
#if 0
printf("intiobase at: %08x\n", intiobase);
printf("intiolimit at: %08x\n", intiolimit);
printf("videobase at: %08x\n", color ? colorbase : monobase);
printf("videolimit at: %08x\n", color ? colorlimit : monolimit);
printf("videobase at: %08x\n", fbbase);
printf("videolimit at: %08x\n", fblimit);

printf("virtual fb at: %08x\n", dc->dc_vaddr);
printf("physical fb at: %08x\n", dc->dc_paddr);
Expand Down Expand Up @@ -231,19 +225,11 @@ nextdisplay_attach(device_t parent, device_t self, void *aux)
struct nextdisplay_softc *sc = device_private(self);
struct wsemuldisplaydev_attach_args waa;
int isconsole;
int iscolor;
paddr_t addr;
vaddr_t addr;

sc->sc_dev = self;

if (rom_machine_type == NeXT_WARP9C ||
rom_machine_type == NeXT_TURBO_COLOR) {
iscolor = 1;
addr = colorbase;
} else {
iscolor = 0;
addr = monobase;
}
addr = fbbase;

isconsole = nextdisplay_is_console(addr);

Expand Down Expand Up @@ -400,13 +386,6 @@ nextdisplay_cnattach(void)
{
struct nextdisplay_config *dc = &nextdisplay_console_dc;
long defattr;
int iscolor;

if (rom_machine_type == NeXT_WARP9C ||
rom_machine_type == NeXT_TURBO_COLOR)
iscolor = 1;
else
iscolor = 0;

/* set up the display */
nextdisplay_init(&nextdisplay_console_dc, iscolor);
Expand Down
25 changes: 4 additions & 21 deletions sys/arch/next68k/include/bus_space.h
Expand Up @@ -81,23 +81,12 @@ typedef u_long bus_space_handle_t;
*/
#define NEXT68K_INTIO_BUS_SPACE ((bus_space_tag_t)intiobase)

/*
* Values for the next68k video bus space tags, not to be used directly
* by MI code.
*/
#define NEXT68K_MONO_VIDEO_BUS_SPACE ((bus_space_tag_t)monobase)
#define NEXT68K_COLOR_VIDEO_BUS_SPACE ((bus_space_tag_t)colorbase)

/*
* Mapping and unmapping operations.
*/
#define bus_space_map(t, a, s, f, hp) \
((((a)>=INTIOBASE)&&((a)+(s)<INTIOTOP)) ? \
((*(hp)=(bus_space_handle_t)((t)+((a)-INTIOBASE))),0) : \
((((a)>=MONOBASE)&&((a)+(s)<MONOTOP)) ? \
((*(hp)=(bus_space_handle_t)((t)+((a)-MONOBASE))),0) : \
((((a)>=COLORBASE)&&((a)+(s)<COLORTOP)) ? \
((*(hp)=(bus_space_handle_t)((t)+((a)-COLORBASE))),0) : (-1))))

int bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int,
bus_space_handle_t *);

#define bus_space_unmap(t, h, s)

Expand All @@ -122,13 +111,7 @@ typedef u_long bus_space_handle_t;
* Mmap an area of bus space.
*/

#define bus_space_mmap(t, a, s, prot, flags) \
((((a)>=INTIOBASE)&&((a)+(s)<INTIOTOP)) ? \
m68k_btop((t)+((a)-INTIOBASE)) : \
((((a)>=MONOBASE)&&((a)+(s)<MONOTOP)) ? \
m68k_btop((t)+((a)-MONOBASE)) : \
((((a)>=COLORBASE)&&((a)+(s)<COLORTOP)) ? \
m68k_btop((t)+((a)-COLORBASE)) : (-1))))
paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int);

/*
* uintN_t bus_space_read_N(bus_space_tag_t tag,
Expand Down
12 changes: 5 additions & 7 deletions sys/arch/next68k/include/cpu.h
Expand Up @@ -120,6 +120,7 @@ void loadustp(int);
void doboot(void) __attribute__((__noreturn__));
int nmihand(void *);

extern int iscolor;
#endif /* _KERNEL */

#define NEXT_RAMBASE (0x4000000) /* really depends on slot, but... */
Expand Down Expand Up @@ -315,7 +316,10 @@ int nmihand(void *);
#define MONOBASE (0x0b000000)
#define MONOTOP (0x0b03a800)
#define COLORBASE (0x2c000000)
#define COLORTOP (0x2c1D4000)
#define COLORTOP (0x2c1d4000)
#define TURBOFBBASE (0x0c000000)
#define TURBOMONOTOP (0x0c03a800)
#define TURBOCOLORTOP (0x0c1d4000)

#define NEXT_INTR_BITS \
"\20\40NMI\37PFAIL\36TIMER\35ENETX_DMA\34ENETR_DMA\33SCSI_DMA\32DISK_DMA\31PRINTER_DMA\30SOUND_OUT_DMA\27SOUND_IN_DMA\26SCC_DMA\25DSP_DMA\24M2R_DMA\23R2M_DMA\22SCC\21REMOTE\20BUS\17DSP_4\16DISK|C16_VIDEO\15SCSI\14PRINTER\13ENETX\12ENETR\11SOUND_OVRUN\10PHONE\07DSP_3\06VIDEO\05MONITOR\04KYBD_MOUSE\03POWER\02SOFTINT1\01SOFTINT0"
Expand All @@ -333,10 +337,4 @@ int nmihand(void *);
#define IIOP(va) ((int)(va)-intiobase+INTIOBASE)
#define IIOMAPSIZE btoc(INTIOTOP-INTIOBASE) /* 2mb */

/* mono fb space */
#define MONOMAPSIZE btoc(MONOTOP-MONOBASE) /* who cares */

/* color fb space */
#define COLORMAPSIZE btoc(COLORTOP-COLORBASE) /* who cares */

#endif /* _MACHINE_CPU_H_ */
16 changes: 8 additions & 8 deletions sys/arch/next68k/next68k/locore.s
Expand Up @@ -1076,17 +1076,17 @@ GLOBAL(intiobase)
GLOBAL(intiolimit)
.long INTIOTOP | KVA of end of internal IO space

GLOBAL(monobase)
.long MONOBASE | KVA of base of mono FB
GLOBAL(fbbase)
.long 0 | KVA of base of framebuffer

GLOBAL(monolimit)
.long MONOTOP | KVA of end of mono FB
GLOBAL(fblimit)
.long 0 | KVA of end of framebuffer

GLOBAL(colorbase)
.long COLORBASE | KVA of base of color FB
GLOBAL(fbbasepa)
.long MONOBASE | PA of base of framebuffer

GLOBAL(colorlimit)
.long COLORTOP | KVA of end of color FB
GLOBAL(fblimitpa)
.long MONOTOP | PA of end of framebuffer

ASLOCAL(save_vbr) | VBR from ROM
.long 0xdeadbeef
Expand Down
31 changes: 29 additions & 2 deletions sys/arch/next68k/next68k/nextrom.c
Expand Up @@ -35,6 +35,7 @@ __KERNEL_RCSID(0, "$NetBSD: nextrom.c,v 1.27 2018/07/18 23:10:27 sevan Exp $");

#include <next68k/next68k/seglist.h>
#include <next68k/next68k/nextrom.h>
#include <next68k/dev/intiovar.h>

#ifdef DDB
#include <sys/param.h>
Expand Down Expand Up @@ -130,6 +131,7 @@ u_int rom_intrstat;
paddr_t rom_reboot_vect;

int turbo;
int iscolor;

void
next68k_bootargs(unsigned char **args)
Expand Down Expand Up @@ -230,6 +232,8 @@ next68k_bootargs(unsigned char **args)
int ix;
int j = 0;
char mach;
int turbo_l, iscolor_l;
paddr_t fbbasepa_l, fblimitpa_l;

if (MONRELOC(char, MG_machine_type) == NeXT_X15) {
msize16 = 0x1000000;
Expand Down Expand Up @@ -267,9 +271,32 @@ next68k_bootargs(unsigned char **args)
mach = MONRELOC(char, MG_machine_type);
RELOC(rom_machine_type, char) = mach;
if (mach == NeXT_TURBO_MONO || mach == NeXT_TURBO_COLOR)
RELOC(turbo, int) = 1;
turbo_l = 1;
else
RELOC(turbo, int) = 0;
turbo_l = 0;
RELOC(turbo, int) = turbo_l;

/* save framebuffer addresses for pmap_bootstrap() */
if (mach == NeXT_WARP9C || mach == NeXT_TURBO_COLOR)
iscolor_l = 1;
else
iscolor_l = 0;
if (turbo_l == 1) {
fbbasepa_l = TURBOFBBASE;
fblimitpa_l = (iscolor_l == 1) ?
TURBOCOLORTOP : TURBOMONOTOP;
} else {
if (iscolor_l == 1) {
fbbasepa_l = COLORBASE;
fblimitpa_l = COLORTOP;
} else {
fbbasepa_l = MONOBASE;
fblimitpa_l = MONOTOP;
}
}
RELOC(iscolor, int) = iscolor_l;
RELOC(fbbasepa, paddr_t) = fbbasepa_l;
RELOC(fblimitpa, paddr_t) = fblimitpa_l;

for (ix = 0; ix < N_SIMM; ix++) {

Expand Down
31 changes: 12 additions & 19 deletions sys/arch/next68k/next68k/pmap_bootstrap.c
Expand Up @@ -108,6 +108,7 @@ pmap_bootstrap(paddr_t nextpa, paddr_t firstpa)
#if defined(M68040) || defined(M68060)
u_int stfree = 0; /* XXX: gcc -Wuninitialized */
#endif
u_int fbmapsize;

/*
* Initialize the mem_clusters[] array for the crash dump
Expand Down Expand Up @@ -178,8 +179,9 @@ pmap_bootstrap(paddr_t nextpa, paddr_t firstpa)
kptmpa = nextpa;
nextpa += PAGE_SIZE;
kptpa = nextpa;
nptpages = RELOC(Sysptsize, int) + howmany(RELOC(physmem, int), NPTEPG) +
(IIOMAPSIZE + MONOMAPSIZE + COLORMAPSIZE + NPTEPG - 1) / NPTEPG;
fbmapsize = btoc(RELOC(fblimitpa, paddr_t) - RELOC(fbbasepa, paddr_t));
nptpages = RELOC(Sysptsize, int) + howmany(RELOC(physmem, int), NPTEPG)
+ (IIOMAPSIZE + fbmapsize + NPTEPG - 1) / NPTEPG;
nextpa += nptpages * PAGE_SIZE;

/*
Expand Down Expand Up @@ -416,29 +418,20 @@ pmap_bootstrap(paddr_t nextpa, paddr_t firstpa)

protopte = INTIOBASE | PG_RW | PG_CI | PG_U | PG_M | PG_V;
epte = &pte[IIOMAPSIZE];
RELOC(intiobase, uint8_t *) = (uint8_t *)PTE2VA(pte);
RELOC(intiolimit, uint8_t *) = (uint8_t *)PTE2VA(epte);
RELOC(intiobase, vaddr_t) = PTE2VA(pte);
RELOC(intiolimit, vaddr_t) = PTE2VA(epte);
while (pte < epte) {
*pte++ = protopte;
protopte += PAGE_SIZE;
}

/* validate the mono fb space PTEs */
/* validate the framebuffer space PTEs */

protopte = MONOBASE | PG_RW | PG_CWT | PG_U | PG_M | PG_V;
epte = &pte[MONOMAPSIZE];
RELOC(monobase, uint8_t *) = (uint8_t *)PTE2VA(pte);
RELOC(monolimit, uint8_t *) = (uint8_t *)PTE2VA(epte);
while (pte < epte) {
*pte++ = protopte;
protopte += PAGE_SIZE;
}

/* validate the color fb space PTEs */
protopte = COLORBASE | PG_RW | PG_CWT | PG_U | PG_M | PG_V;
epte = &pte[COLORMAPSIZE];
RELOC(colorbase, uint8_t *) = (uint8_t *)PTE2VA(pte);
RELOC(colorlimit, uint8_t *) = (uint8_t *)PTE2VA(epte);
protopte = RELOC(fbbasepa, paddr_t) |
PG_RW | PG_CWT | PG_U | PG_M | PG_V;
epte = &pte[fbmapsize];
RELOC(fbbase, vaddr_t) = PTE2VA(pte);
RELOC(fblimit, vaddr_t) = PTE2VA(epte);
while (pte < epte) {
*pte++ = protopte;
protopte += PAGE_SIZE;
Expand Down

0 comments on commit 58a2e85

Please sign in to comment.