2006-05-04 22:07:30 +00:00
|
|
|
/*
|
|
|
|
|
* OpenBIOS ESP driver
|
2008-07-07 18:35:51 +00:00
|
|
|
*
|
2006-05-04 22:07:30 +00:00
|
|
|
* Copyright (C) 2004 Jens Axboe <axboe@suse.de>
|
|
|
|
|
* Copyright (C) 2005 Stefan Reinauer <stepan@openbios.org>
|
|
|
|
|
*
|
|
|
|
|
* Credit goes to Hale Landis for his excellent ata demo software
|
|
|
|
|
* OF node handling and some fixes by Stefan Reinauer
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* version 2
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2010-03-14 17:19:58 +00:00
|
|
|
#include "config.h"
|
2010-03-14 15:05:53 +00:00
|
|
|
#include "libopenbios/bindings.h"
|
2010-03-14 14:21:02 +00:00
|
|
|
#include "kernel/kernel.h"
|
2006-05-04 22:07:30 +00:00
|
|
|
#include "libc/byteorder.h"
|
|
|
|
|
#include "libc/vsprintf.h"
|
|
|
|
|
|
2010-03-14 15:19:41 +00:00
|
|
|
#include "drivers/drivers.h"
|
2006-05-07 16:40:13 +00:00
|
|
|
#include "asm/io.h"
|
2006-05-06 21:33:36 +00:00
|
|
|
#include "scsi.h"
|
2006-05-04 22:07:30 +00:00
|
|
|
#include "asm/dma.h"
|
2006-05-06 21:33:36 +00:00
|
|
|
#include "esp.h"
|
2010-03-14 15:05:53 +00:00
|
|
|
#include "libopenbios/ofmem.h"
|
2006-05-04 22:07:30 +00:00
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
#define BUFSIZE 4096
|
2006-05-04 22:07:30 +00:00
|
|
|
|
2006-05-16 17:36:09 +00:00
|
|
|
#ifdef CONFIG_DEBUG_ESP
|
|
|
|
|
#define DPRINTF(fmt, args...) \
|
|
|
|
|
do { printk(fmt , ##args); } while (0)
|
|
|
|
|
#else
|
|
|
|
|
#define DPRINTF(fmt, args...)
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-05-04 22:07:30 +00:00
|
|
|
struct esp_dma {
|
2006-05-06 21:33:36 +00:00
|
|
|
volatile struct sparc_dma_registers *regs;
|
2006-05-04 22:07:30 +00:00
|
|
|
enum dvma_rev revision;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct sd_private {
|
2006-05-06 21:33:36 +00:00
|
|
|
unsigned int bs;
|
2009-01-06 20:27:01 +00:00
|
|
|
const char *media_str[2];
|
2006-05-06 21:33:36 +00:00
|
|
|
uint32_t sectors;
|
|
|
|
|
uint8_t media;
|
|
|
|
|
uint8_t id;
|
|
|
|
|
uint8_t present;
|
|
|
|
|
char model[40];
|
2006-05-04 22:07:30 +00:00
|
|
|
} sd_private_t;
|
|
|
|
|
|
|
|
|
|
struct esp_regs {
|
2006-05-06 21:33:36 +00:00
|
|
|
unsigned char regs[ESP_REG_SIZE];
|
2006-05-04 22:07:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct esp_private {
|
|
|
|
|
volatile struct esp_regs *ll;
|
2006-05-06 21:33:36 +00:00
|
|
|
uint32_t buffer_dvma;
|
2006-05-04 22:07:30 +00:00
|
|
|
unsigned int irq; /* device IRQ number */
|
2006-05-06 21:33:36 +00:00
|
|
|
struct esp_dma espdma;
|
2006-05-04 22:07:30 +00:00
|
|
|
unsigned char *buffer;
|
2006-05-06 21:33:36 +00:00
|
|
|
sd_private_t sd[8];
|
2006-05-04 22:07:30 +00:00
|
|
|
} esp_private_t;
|
|
|
|
|
|
2008-11-30 11:54:01 +00:00
|
|
|
static esp_private_t *global_esp;
|
2006-05-06 21:33:36 +00:00
|
|
|
|
2006-05-04 22:07:30 +00:00
|
|
|
/* DECLARE data structures for the nodes. */
|
2006-05-06 21:33:36 +00:00
|
|
|
DECLARE_UNNAMED_NODE(ob_sd, INSTALL_OPEN, sizeof(sd_private_t *));
|
|
|
|
|
DECLARE_UNNAMED_NODE(ob_esp, INSTALL_OPEN, sizeof(esp_private_t *));
|
|
|
|
|
|
2006-05-10 23:00:34 +00:00
|
|
|
#ifdef CONFIG_DEBUG_ESP
|
2006-05-06 21:33:36 +00:00
|
|
|
static void dump_drive(sd_private_t *drive)
|
|
|
|
|
{
|
|
|
|
|
printk("SCSI DRIVE @%lx:\n", (unsigned long)drive);
|
|
|
|
|
printk("id: %d\n", drive->id);
|
2009-01-06 20:27:01 +00:00
|
|
|
printk("media: %s\n", drive->media_str[0]);
|
|
|
|
|
printk("media: %s\n", drive->media_str[1]);
|
2006-05-06 21:33:36 +00:00
|
|
|
printk("model: %s\n", drive->model);
|
|
|
|
|
printk("sectors: %d\n", drive->sectors);
|
|
|
|
|
printk("present: %d\n", drive->present);
|
|
|
|
|
printk("bs: %d\n", drive->bs);
|
|
|
|
|
}
|
2006-05-10 23:00:34 +00:00
|
|
|
#endif
|
2006-05-04 22:07:30 +00:00
|
|
|
|
|
|
|
|
static int
|
2006-05-06 21:33:36 +00:00
|
|
|
do_command(esp_private_t *esp, sd_private_t *sd, int cmdlen, int replylen)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
2006-05-06 21:33:36 +00:00
|
|
|
int status;
|
2006-05-04 22:07:30 +00:00
|
|
|
|
|
|
|
|
// Set SCSI target
|
2006-05-06 21:33:36 +00:00
|
|
|
esp->ll->regs[ESP_BUSID] = sd->id & 7;
|
2006-05-04 22:07:30 +00:00
|
|
|
// Set DMA address
|
2006-05-06 21:33:36 +00:00
|
|
|
esp->espdma.regs->st_addr = esp->buffer_dvma;
|
2006-05-04 22:07:30 +00:00
|
|
|
// Set DMA length
|
2006-05-06 21:33:36 +00:00
|
|
|
esp->ll->regs[ESP_TCLOW] = cmdlen & 0xff;
|
|
|
|
|
esp->ll->regs[ESP_TCMED] = (cmdlen >> 8) & 0xff;
|
2006-05-04 22:07:30 +00:00
|
|
|
// Set DMA direction
|
2006-05-06 21:33:36 +00:00
|
|
|
esp->espdma.regs->cond_reg = 0;
|
2006-05-04 22:07:30 +00:00
|
|
|
// Set ATN, issue command
|
2006-05-06 21:33:36 +00:00
|
|
|
esp->ll->regs[ESP_CMD] = ESP_CMD_SELA | ESP_CMD_DMA;
|
2006-08-12 09:52:34 +00:00
|
|
|
// Wait for DMA to complete. Can this fail?
|
|
|
|
|
while ((esp->espdma.regs->cond_reg & DMA_HNDL_INTR) == 0) /* no-op */;
|
2006-05-06 21:33:36 +00:00
|
|
|
// Check status
|
|
|
|
|
status = esp->ll->regs[ESP_STATUS];
|
2010-01-16 10:35:58 +00:00
|
|
|
// Clear interrupts to avoid guests seeing spurious interrupts
|
|
|
|
|
(void)esp->ll->regs[ESP_INTRPT];
|
2006-05-04 22:07:30 +00:00
|
|
|
|
2006-08-20 15:59:02 +00:00
|
|
|
DPRINTF("do_command: id %d, cmd[0] 0x%x, status 0x%x\n", sd->id, esp->buffer[0], status);
|
|
|
|
|
|
|
|
|
|
// Target didn't want all command data or went to status phase
|
|
|
|
|
// instead of data phase?
|
|
|
|
|
if ((status & ESP_STAT_TCNT) != ESP_STAT_TCNT
|
|
|
|
|
|| (status & ESP_STAT_PMASK) == ESP_STATP)
|
2006-05-06 21:33:36 +00:00
|
|
|
return status;
|
2008-07-07 18:35:51 +00:00
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
// Get reply
|
|
|
|
|
// Set DMA address
|
|
|
|
|
esp->espdma.regs->st_addr = esp->buffer_dvma;
|
2006-05-04 22:07:30 +00:00
|
|
|
// Set DMA length
|
2006-05-06 21:33:36 +00:00
|
|
|
esp->ll->regs[ESP_TCLOW] = replylen & 0xff;
|
|
|
|
|
esp->ll->regs[ESP_TCMED] = (replylen >> 8) & 0xff;
|
2006-05-04 22:07:30 +00:00
|
|
|
// Set DMA direction
|
2006-05-06 21:33:36 +00:00
|
|
|
esp->espdma.regs->cond_reg = DMA_ST_WRITE;
|
2006-05-04 22:07:30 +00:00
|
|
|
// Transfer
|
2006-05-06 21:33:36 +00:00
|
|
|
esp->ll->regs[ESP_CMD] = ESP_CMD_TI | ESP_CMD_DMA;
|
2006-08-12 09:52:34 +00:00
|
|
|
// Wait for DMA to complete
|
|
|
|
|
while ((esp->espdma.regs->cond_reg & DMA_HNDL_INTR) == 0) /* no-op */;
|
2006-05-06 21:33:36 +00:00
|
|
|
// Check status
|
|
|
|
|
status = esp->ll->regs[ESP_STATUS];
|
2010-01-16 10:35:58 +00:00
|
|
|
// Clear interrupts to avoid guests seeing spurious interrupts
|
|
|
|
|
(void)esp->ll->regs[ESP_INTRPT];
|
2006-05-06 21:33:36 +00:00
|
|
|
|
2006-08-20 15:59:02 +00:00
|
|
|
DPRINTF("do_command_reply: status 0x%x\n", status);
|
|
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
if ((status & ESP_STAT_TCNT) != ESP_STAT_TCNT)
|
|
|
|
|
return status;
|
|
|
|
|
else
|
|
|
|
|
return 0; // OK
|
2006-05-04 22:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-10 17:43:11 +00:00
|
|
|
// offset is in sectors
|
2006-05-06 21:33:36 +00:00
|
|
|
static int
|
2006-10-10 17:43:11 +00:00
|
|
|
ob_sd_read_sector(esp_private_t *esp, sd_private_t *sd, int offset)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
2009-07-20 06:52:23 +00:00
|
|
|
DPRINTF("ob_sd_read_sector id %d sector=%d\n",
|
|
|
|
|
sd->id, offset);
|
2006-05-16 17:36:09 +00:00
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
// Setup command = Read(10)
|
|
|
|
|
memset(esp->buffer, 0, 10);
|
|
|
|
|
esp->buffer[0] = 0x80;
|
|
|
|
|
esp->buffer[1] = READ_10;
|
2006-05-04 22:07:30 +00:00
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
esp->buffer[3] = (offset >> 24) & 0xff;
|
|
|
|
|
esp->buffer[4] = (offset >> 16) & 0xff;
|
|
|
|
|
esp->buffer[5] = (offset >> 8) & 0xff;
|
|
|
|
|
esp->buffer[6] = offset & 0xff;
|
2006-05-04 22:07:30 +00:00
|
|
|
|
2006-10-10 17:43:11 +00:00
|
|
|
esp->buffer[8] = 0;
|
|
|
|
|
esp->buffer[9] = 1;
|
2006-05-06 21:33:36 +00:00
|
|
|
|
2006-10-10 17:43:11 +00:00
|
|
|
if (do_command(esp, sd, 10, sd->bs))
|
2006-05-06 21:33:36 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2006-05-04 22:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
static unsigned int
|
|
|
|
|
read_capacity(esp_private_t *esp, sd_private_t *sd)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
2006-05-06 21:33:36 +00:00
|
|
|
// Setup command = Read Capacity
|
|
|
|
|
memset(esp->buffer, 0, 11);
|
|
|
|
|
esp->buffer[0] = 0x80;
|
|
|
|
|
esp->buffer[1] = READ_CAPACITY;
|
|
|
|
|
|
|
|
|
|
if (do_command(esp, sd, 11, 8)) {
|
|
|
|
|
sd->sectors = 0;
|
|
|
|
|
sd->bs = 0;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
sd->bs = (esp->buffer[4] << 24) | (esp->buffer[5] << 16) | (esp->buffer[6] << 8) | esp->buffer[7];
|
2006-05-25 21:02:53 +00:00
|
|
|
sd->sectors = ((esp->buffer[0] << 24) | (esp->buffer[1] << 16) | (esp->buffer[2] << 8) | esp->buffer[3]) * (sd->bs / 512);
|
2006-05-06 21:33:36 +00:00
|
|
|
|
|
|
|
|
return 1;
|
2006-05-04 22:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned int
|
2006-05-06 21:33:36 +00:00
|
|
|
inquiry(esp_private_t *esp, sd_private_t *sd)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
2009-01-06 20:27:01 +00:00
|
|
|
const char *media[2] = { "UNKNOWN", "UNKNOWN"};
|
2006-05-04 22:07:30 +00:00
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
// Setup command = Inquiry
|
|
|
|
|
memset(esp->buffer, 0, 7);
|
|
|
|
|
esp->buffer[0] = 0x80;
|
|
|
|
|
esp->buffer[1] = INQUIRY;
|
|
|
|
|
|
2006-05-28 18:48:47 +00:00
|
|
|
esp->buffer[5] = 36;
|
2006-05-06 21:33:36 +00:00
|
|
|
|
|
|
|
|
if (do_command(esp, sd, 7, 36)) {
|
|
|
|
|
sd->present = 0;
|
|
|
|
|
sd->media = -1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
sd->present = 1;
|
|
|
|
|
sd->media = esp->buffer[0];
|
2008-07-07 18:35:51 +00:00
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
switch (sd->media) {
|
|
|
|
|
case TYPE_DISK:
|
2009-01-06 20:27:01 +00:00
|
|
|
media[0] = "disk";
|
|
|
|
|
media[1] = "hd";
|
2006-05-06 21:33:36 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_ROM:
|
2009-01-06 20:27:01 +00:00
|
|
|
media[0] = "cdrom";
|
|
|
|
|
media[1] = "cd";
|
2006-05-06 21:33:36 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2009-01-06 20:27:01 +00:00
|
|
|
sd->media_str[0] = media[0];
|
|
|
|
|
sd->media_str[1] = media[1];
|
2006-05-06 21:33:36 +00:00
|
|
|
memcpy(sd->model, &esp->buffer[16], 16);
|
|
|
|
|
sd->model[17] = '\0';
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ob_sd_read_blocks(sd_private_t **sd)
|
|
|
|
|
{
|
2006-05-07 16:40:13 +00:00
|
|
|
cell n = POP(), cnt = n;
|
2006-05-06 21:33:36 +00:00
|
|
|
ucell blk = POP();
|
|
|
|
|
char *dest = (char*)POP();
|
2006-05-25 21:02:53 +00:00
|
|
|
int pos, spb, sect_offset;
|
2006-05-06 21:33:36 +00:00
|
|
|
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("ob_sd_read_blocks id %d %lx block=%d n=%d\n", (*sd)->id, (unsigned long)dest, blk, n );
|
2006-05-07 16:40:13 +00:00
|
|
|
|
2006-05-25 21:02:53 +00:00
|
|
|
spb = (*sd)->bs / 512;
|
2006-05-07 16:40:13 +00:00
|
|
|
while (n) {
|
2006-05-25 21:02:53 +00:00
|
|
|
sect_offset = blk / spb;
|
|
|
|
|
pos = (blk - sect_offset * spb) * 512;
|
|
|
|
|
|
2006-10-10 17:43:11 +00:00
|
|
|
if (ob_sd_read_sector(global_esp, *sd, sect_offset)) {
|
2006-05-25 21:02:53 +00:00
|
|
|
DPRINTF("ob_sd_read_blocks: error\n");
|
2006-05-07 16:40:13 +00:00
|
|
|
RET(0);
|
|
|
|
|
}
|
2006-10-10 17:43:11 +00:00
|
|
|
while (n && pos < spb * 512) {
|
|
|
|
|
memcpy(dest, global_esp->buffer + pos, 512);
|
|
|
|
|
pos += 512;
|
|
|
|
|
dest += 512;
|
|
|
|
|
n--;
|
|
|
|
|
blk++;
|
|
|
|
|
}
|
2006-05-06 21:33:36 +00:00
|
|
|
}
|
2006-05-07 16:40:13 +00:00
|
|
|
PUSH(cnt);
|
2006-05-06 21:33:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-05-25 21:02:53 +00:00
|
|
|
ob_sd_block_size(__attribute__((unused))sd_private_t **sd)
|
2006-05-06 21:33:36 +00:00
|
|
|
{
|
2006-05-25 21:02:53 +00:00
|
|
|
PUSH(512);
|
2006-05-04 22:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-05-06 21:33:36 +00:00
|
|
|
ob_sd_open(__attribute__((unused))sd_private_t **sd)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
2006-05-06 21:33:36 +00:00
|
|
|
int ret = 1, id;
|
2006-05-04 22:07:30 +00:00
|
|
|
phandle_t ph;
|
|
|
|
|
|
|
|
|
|
fword("my-unit");
|
2008-07-07 18:35:51 +00:00
|
|
|
id = POP();
|
2010-07-31 22:48:10 +00:00
|
|
|
POP(); // unit id is 2 ints but we only need one.
|
2006-05-06 21:33:36 +00:00
|
|
|
*sd = &global_esp->sd[id];
|
2006-05-04 22:07:30 +00:00
|
|
|
|
2006-05-22 10:37:34 +00:00
|
|
|
#ifdef CONFIG_DEBUG_ESP
|
2007-06-27 20:16:01 +00:00
|
|
|
{
|
|
|
|
|
char *args;
|
|
|
|
|
|
|
|
|
|
fword("my-args");
|
|
|
|
|
args = pop_fstr_copy();
|
|
|
|
|
DPRINTF("opening drive %d args %s\n", id, args);
|
|
|
|
|
free(args);
|
|
|
|
|
}
|
2006-05-22 10:37:34 +00:00
|
|
|
#endif
|
2006-05-16 17:36:09 +00:00
|
|
|
|
2006-05-04 22:07:30 +00:00
|
|
|
selfword("open-deblocker");
|
|
|
|
|
|
|
|
|
|
/* interpose disk-label */
|
|
|
|
|
ph = find_dev("/packages/disk-label");
|
|
|
|
|
fword("my-args");
|
|
|
|
|
PUSH_ph( ph );
|
|
|
|
|
fword("interpose");
|
Patch for SunOS compatibility from pjcreath+openbios@gmail.com:
I've been trying to get old versions of SunOS to load under qemu. In
doing so, I've encountered a number of bugs in OBP. I'm not always
certain of the best fix, but I can at least provide a quick hack that
will get people farther along.
1) Error message: "kmem_alloc failed, nbytes 680"
Bug: obp_dumb_memalloc is a bit too dumb. It needs to pick an address
if passed a null address. (According to the comment in the allocator
in OpenSolaris prom_alloc.c (see
<http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/psm/promif/ieee1275/sun4/prom_alloc.c>),
"If virthint is zero, a suitable virt is chosen.")
Quick fix: If passed a null address, start doling out addresses at
10MB and increment by size.
Shortcomings: The quick fix ignores the issue of free() and doesn't
remove memory from the virtual-memory/available node.
After the quick fix, the boot gets farther, leading us to:
2) Error message: "Unhandled Exception 0x00000080"
Bug: Trap 0 (entry 0x80 in the table, i.e. syscall_trap_4x) is
undefined. This is because the SunOS bootloader installs the trap by
writing code in the trap table, but the trap table is in the .text
section of OpenBIOS. Thus the trap 0 handler simply jumps to "bug".
Quick fix: Move the trap table to the .data section. Insert a "b
entry; nop; nop; nop;" before "bug:".
Shortcomings: Requires the extra "b entry" code. Allows the only VM
copy of the trap table to be permanently changed. OpenBIOS should
copy the read-only trap table to read-write memory (and update %tbr)
upon reset/entry.
3) #2 above actually exposes another bug. The write to the read-only
trap table does not cause an access violation -- instead, it silently
fails. The "std" instruction at 0x403e6c in the bootloader has no
effect.
Bug: Uncertain. It could be a systemic bug in qemu, but it appears
that the VM's MMU believes that the page is writable. That means that
the VM's MMU is not having the access protection flags set for pages
mapped to ROM. It thinks everything is rwx.
Fix?: The VM's MMU should have the access protection flags properly
set for each ROM section. This should probably be done within
OpenBIOS. E.g., .text should be r-x, .data should probably be rwx,
etc.
This is the one fix I'm really not sure how to implement. Any
suggestions? This may be a problem that only affects this bootloader,
so fixing #2 above may be all that's strictly necessary. But I'm not
positive that this bug doesn't have other ill effects I haven't found
yet.
At any rate, fixing #2 gets us still further, to:
4) Error messages:
"obp_devopen(sd(0,0,0):d) = 0xffd8e270
obp_inst2pkg(fd 0xffd8e270) = 0xffd57f44
obp_getprop(0xffd57f44, device_type) (not found)"
Bug: The OpenBIOS "interpose" implementation is not transparent to
non-interposition-aware code (in violation of the interposition spec).
The inst2pkg call in this sequence returns the phandle for
/packages/misc-files, instead of the proper phandle.
Quick fix: Comment out the "interpose disk-label" lines in ob_sd_open.
Shortcomings: It disables disk-label. The correct fix is to fix the
underlying problem with interposition, but I'm not sure exactly what
it is. Could someone help?
Fixing #4 gets us quite a bit further, until:
5) Error message:
"Unhandled Exception 0x00000009
PC = 0xf0138b20 NPC = 0xf0138b24
Stopping execution"
Bug: The instruction is trying to read from 0xfd020000+4, which is an
invalid address. This address isn't mapped by OBP by default on Sun
hardware, so the bootloader must be trying to (a) map this address and
failing silently or (b) skipping the mapping for some reason. The
instruction is hard-coded to look at this absolute address.
Fix: Unknown. This may be another instance of writes silently
failing, hence my interest in #3 above. It could also be a
side-effect of the quick fix for #4.
6) Error message:
"BAD TRAP: cpu=0 type=9 rp=fd008f0c addr=feff8008 mmu_fsr=3a6 rw=2
MMU sfsr=3a6: Invalid Address on supv data store at level 3
regs at fd008f0c:
psr=4400fc7 pc=f00053f4 npc=f00053f8
..."
Bug: Real sun4m hardware registers 4 CPU-specific interrupts followed
by a system-wide interrupt, regardless of the number of CPUs
installed. The same is true of counters. SunOS looks at the 5th
interrupt for the system-wide interrupt. OBP, since there's only one
CPU, just sets up one CPU-specific interrupt followed by the
system-wide interrupt, so there is no 5th interrupt. See the comment
on "NCPU" at
<http://stuff.mit.edu/afs/athena/astaff/project/opssrc/sys.sunos/sun4m/devaddr.h>.
Fix: in obp_interrupt_init() and obp_counter_init() register 4
CPU-specific interrupts before allocating the system-wide interrupt.
The kernel will then map the 5th interrupt to the system-wide
interrupt.
7) Error message:
"BAD TRAP: cpu=0 type=9 rp=fd008d8c addr=7ff000 mmu_fsr=126 rw=1
MMU sfsr=126: Invalid Address on supv data fetch at level 1
regs at fd008d8c:
psr=4000cc4 pc=f01339a4 npc=f01339a8
..."
Bug: The command-line arguments passed to the kernel are fixed at
address 0x7FF000 (CMDLINE_ADDR, passed from qemu via nv_info.cmdline),
which is no longer mapped by the time the kernel looks at the boot
arguments. A regular Sun boot ROM will copy this into mapped memory.
Fix: Copy the string in nv_info.cmdline to a OpenBIOS global (since
OpenBIOS continues to be mapped) in ob_nvram_init().
8) Error message:
"BAD TRAP: cpu=0 type=9 rp=fd008dec addr=1019000 mmu_fsr=126 rw=1
MMU sfsr=126: Invalid Address on supv data fetch at level 1
regs at fd008dec:
psr=4400cc5 pc=f0131680 npc=f0131684
..."
Bug: The dumb memory allocator from bug #1 was allocating a range that
the SunOS 4 kernel doesn't like.
Fix: Mimic the Sun boot ROM allocator: the top of the heap should be
a 0xFFEDA000 and allocations should return descending addresses. So,
for example, if asking for 0x1000 bytes, the first returned pointer
should be 0xFFED9000.
9) Error message:
"BAD TRAP: cpu=0 type=9 rp=fd008d2c addr=b1b91000 mmu_fsr=126 rw=1
MMU sfsr=126: Invalid Address on supv data fetch at level 1
regs at fd008d2c:
psr=4900cc3 pc=f0142c04 npc=f0142c08
..."
Bug: The precise underlying cause isn't clear. The bug appears due to
a variation between OBP's behavior and stock Sun behavior.
Fix: Add the "cache-physical?" property to the CPU node in
ob_nvram_init() and bump the "mmu-nctx" property up to 4096 (from
256).
git-svn-id: svn://coreboot.org/openbios/openbios-devel@114 f158a5a8-5612-0410-a976-696ce0be7e32
2007-03-09 00:59:05 +00:00
|
|
|
|
2006-05-04 22:07:30 +00:00
|
|
|
RET ( -ret );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-05-06 21:33:36 +00:00
|
|
|
ob_sd_close(__attribute__((unused)) sd_private_t **sd)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
|
|
|
|
selfword("close-deblocker");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NODE_METHODS(ob_sd) = {
|
|
|
|
|
{ "open", ob_sd_open },
|
|
|
|
|
{ "close", ob_sd_close },
|
|
|
|
|
{ "read-blocks", ob_sd_read_blocks },
|
|
|
|
|
{ "block-size", ob_sd_block_size },
|
|
|
|
|
};
|
|
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
|
|
|
|
|
static int
|
2007-05-19 12:55:01 +00:00
|
|
|
espdma_init(unsigned int slot, uint64_t base, unsigned long offset,
|
2007-04-09 12:35:41 +00:00
|
|
|
struct esp_dma *espdma)
|
2006-05-06 21:33:36 +00:00
|
|
|
{
|
2007-11-11 18:02:11 +00:00
|
|
|
espdma->regs = (void *)map_io(base + (uint64_t)offset, 0x10);
|
2006-05-06 21:33:36 +00:00
|
|
|
|
2008-11-30 11:54:01 +00:00
|
|
|
if (espdma->regs == NULL) {
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("espdma_init: cannot map registers\n");
|
2006-05-06 21:33:36 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("dma1: ");
|
2006-05-06 21:33:36 +00:00
|
|
|
|
|
|
|
|
switch ((espdma->regs->cond_reg) & DMA_DEVICE_ID) {
|
|
|
|
|
case DMA_VERS0:
|
|
|
|
|
espdma->revision = dvmarev0;
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("Revision 0 ");
|
2006-05-06 21:33:36 +00:00
|
|
|
break;
|
|
|
|
|
case DMA_ESCV1:
|
|
|
|
|
espdma->revision = dvmaesc1;
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("ESC Revision 1 ");
|
2006-05-06 21:33:36 +00:00
|
|
|
break;
|
|
|
|
|
case DMA_VERS1:
|
|
|
|
|
espdma->revision = dvmarev1;
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("Revision 1 ");
|
2006-05-06 21:33:36 +00:00
|
|
|
break;
|
|
|
|
|
case DMA_VERS2:
|
|
|
|
|
espdma->revision = dvmarev2;
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("Revision 2 ");
|
2006-05-06 21:33:36 +00:00
|
|
|
break;
|
|
|
|
|
case DMA_VERHME:
|
|
|
|
|
espdma->revision = dvmahme;
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("HME DVMA gate array ");
|
2006-05-06 21:33:36 +00:00
|
|
|
break;
|
|
|
|
|
case DMA_VERSPLUS:
|
|
|
|
|
espdma->revision = dvmarevplus;
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("Revision 1 PLUS ");
|
2006-05-06 21:33:36 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("unknown dma version %x",
|
2006-05-06 21:33:36 +00:00
|
|
|
(espdma->regs->cond_reg) & DMA_DEVICE_ID);
|
|
|
|
|
/* espdma->allocated = 1; */
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("\n");
|
2006-05-06 21:33:36 +00:00
|
|
|
|
2006-05-22 22:10:54 +00:00
|
|
|
push_str("/iommu/sbus/espdma");
|
|
|
|
|
fword("find-device");
|
|
|
|
|
|
|
|
|
|
/* set reg */
|
2007-04-09 12:35:41 +00:00
|
|
|
PUSH(slot);
|
2006-05-22 22:10:54 +00:00
|
|
|
fword("encode-int");
|
2007-11-11 18:02:11 +00:00
|
|
|
PUSH(offset);
|
2006-05-22 22:10:54 +00:00
|
|
|
fword("encode-int");
|
|
|
|
|
fword("encode+");
|
|
|
|
|
PUSH(0x00000010);
|
|
|
|
|
fword("encode-int");
|
|
|
|
|
fword("encode+");
|
|
|
|
|
push_str("reg");
|
|
|
|
|
fword("property");
|
|
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-04 22:07:30 +00:00
|
|
|
static void
|
2006-05-06 21:33:36 +00:00
|
|
|
ob_esp_initialize(__attribute__((unused)) esp_private_t **esp)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
2006-05-06 21:33:36 +00:00
|
|
|
phandle_t ph = get_cur_dev();
|
2006-05-04 22:07:30 +00:00
|
|
|
|
|
|
|
|
set_int_property(ph, "#address-cells", 2);
|
|
|
|
|
set_int_property(ph, "#size-cells", 0);
|
|
|
|
|
|
|
|
|
|
/* set device type */
|
|
|
|
|
push_str("scsi");
|
|
|
|
|
fword("device-type");
|
|
|
|
|
|
2006-05-18 21:57:08 +00:00
|
|
|
PUSH(0x24);
|
|
|
|
|
fword("encode-int");
|
|
|
|
|
PUSH(0);
|
|
|
|
|
fword("encode-int");
|
|
|
|
|
fword("encode+");
|
|
|
|
|
push_str("intr");
|
|
|
|
|
fword("property");
|
2006-05-04 22:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-05-06 21:33:36 +00:00
|
|
|
ob_esp_decodeunit(__attribute__((unused)) esp_private_t **esp)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
|
|
|
|
fword("decode-unit-scsi");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-05-06 21:33:36 +00:00
|
|
|
ob_esp_encodeunit(__attribute__((unused)) esp_private_t **esp)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
|
|
|
|
fword("encode-unit-scsi");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NODE_METHODS(ob_esp) = {
|
|
|
|
|
{ NULL, ob_esp_initialize },
|
|
|
|
|
{ "decode-unit", ob_esp_decodeunit },
|
|
|
|
|
{ "encode-unit", ob_esp_encodeunit },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
2006-05-22 10:37:34 +00:00
|
|
|
add_alias(const char *device, const char *alias)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
2009-01-06 20:27:01 +00:00
|
|
|
DPRINTF("add_alias dev \"%s\" = alias \"%s\"\n", device, alias);
|
2006-05-04 22:07:30 +00:00
|
|
|
push_str("/aliases");
|
|
|
|
|
fword("find-device");
|
|
|
|
|
push_str(device);
|
|
|
|
|
fword("encode-string");
|
|
|
|
|
push_str(alias);
|
|
|
|
|
fword("property");
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-22 22:10:54 +00:00
|
|
|
int
|
2007-11-11 18:02:11 +00:00
|
|
|
ob_esp_init(unsigned int slot, uint64_t base, unsigned long espoffset,
|
|
|
|
|
unsigned long dmaoffset)
|
2006-05-04 22:07:30 +00:00
|
|
|
{
|
|
|
|
|
int id, diskcount = 0, cdcount = 0, *counter_ptr;
|
|
|
|
|
char nodebuff[256], aliasbuff[256];
|
2006-05-06 21:33:36 +00:00
|
|
|
esp_private_t *esp;
|
2006-05-04 22:07:30 +00:00
|
|
|
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("Initializing SCSI...");
|
2006-05-06 21:33:36 +00:00
|
|
|
|
|
|
|
|
esp = malloc(sizeof(esp_private_t));
|
2006-05-22 10:37:34 +00:00
|
|
|
if (!esp) {
|
|
|
|
|
DPRINTF("Can't allocate ESP private structure\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-06 21:33:36 +00:00
|
|
|
global_esp = esp;
|
|
|
|
|
|
2007-11-11 18:02:11 +00:00
|
|
|
if (espdma_init(slot, base, dmaoffset, &esp->espdma) != 0) {
|
2006-05-06 21:33:36 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
/* Get the IO region */
|
2007-11-11 18:02:11 +00:00
|
|
|
esp->ll = (void *)map_io(base + (uint64_t)espoffset,
|
2007-05-19 12:55:01 +00:00
|
|
|
sizeof(struct esp_regs));
|
2008-11-30 11:54:01 +00:00
|
|
|
if (esp->ll == NULL) {
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("Can't map ESP registers\n");
|
2006-05-06 21:33:36 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
esp->buffer = (void *)dvma_alloc(BUFSIZE, &esp->buffer_dvma);
|
|
|
|
|
if (!esp->buffer || !esp->buffer_dvma) {
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("Can't get a DVMA buffer\n");
|
2006-05-06 21:33:36 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Chip reset
|
|
|
|
|
esp->ll->regs[ESP_CMD] = ESP_CMD_RC;
|
2008-07-07 18:35:51 +00:00
|
|
|
|
2006-05-22 10:37:34 +00:00
|
|
|
DPRINTF("ESP at 0x%lx, buffer va 0x%lx dva 0x%lx\n", (unsigned long)esp,
|
|
|
|
|
(unsigned long)esp->buffer, (unsigned long)esp->buffer_dvma);
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("done\n");
|
|
|
|
|
DPRINTF("Initializing SCSI devices...");
|
2006-05-06 21:33:36 +00:00
|
|
|
|
|
|
|
|
for (id = 0; id < 8; id++) {
|
|
|
|
|
esp->sd[id].id = id;
|
|
|
|
|
if (!inquiry(esp, &esp->sd[id]))
|
|
|
|
|
continue;
|
|
|
|
|
read_capacity(esp, &esp->sd[id]);
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_ESP
|
|
|
|
|
dump_drive(&esp->sd[id]);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-22 10:37:34 +00:00
|
|
|
REGISTER_NAMED_NODE(ob_esp, "/iommu/sbus/espdma/esp");
|
2006-05-06 21:33:36 +00:00
|
|
|
device_end();
|
2007-04-09 12:35:41 +00:00
|
|
|
/* set reg */
|
|
|
|
|
push_str("/iommu/sbus/espdma/esp");
|
|
|
|
|
fword("find-device");
|
|
|
|
|
PUSH(slot);
|
|
|
|
|
fword("encode-int");
|
2007-11-11 18:02:11 +00:00
|
|
|
PUSH(espoffset);
|
2007-04-09 12:35:41 +00:00
|
|
|
fword("encode-int");
|
|
|
|
|
fword("encode+");
|
|
|
|
|
PUSH(0x00000010);
|
|
|
|
|
fword("encode-int");
|
|
|
|
|
fword("encode+");
|
|
|
|
|
push_str("reg");
|
|
|
|
|
fword("property");
|
2006-05-06 21:33:36 +00:00
|
|
|
|
2007-05-17 19:16:06 +00:00
|
|
|
PUSH(0x02625a00);
|
|
|
|
|
fword("encode-int");
|
|
|
|
|
push_str("clock-frequency");
|
|
|
|
|
fword("property");
|
|
|
|
|
|
2006-05-04 22:07:30 +00:00
|
|
|
for (id = 0; id < 8; id++) {
|
2006-05-06 21:33:36 +00:00
|
|
|
if (!esp->sd[id].present)
|
2006-05-04 22:07:30 +00:00
|
|
|
continue;
|
|
|
|
|
push_str("/iommu/sbus/espdma/esp");
|
|
|
|
|
fword("find-device");
|
|
|
|
|
fword("new-device");
|
|
|
|
|
push_str("sd");
|
|
|
|
|
fword("device-name");
|
|
|
|
|
push_str("block");
|
|
|
|
|
fword("device-type");
|
|
|
|
|
fword("is-deblocker");
|
|
|
|
|
PUSH(id);
|
|
|
|
|
fword("encode-int");
|
|
|
|
|
PUSH(0);
|
|
|
|
|
fword("encode-int");
|
|
|
|
|
fword("encode+");
|
|
|
|
|
push_str("reg");
|
|
|
|
|
fword("property");
|
|
|
|
|
fword("finish-device");
|
2008-11-30 13:44:38 +00:00
|
|
|
snprintf(nodebuff, sizeof(nodebuff), "/iommu/sbus/espdma/esp/sd@%d,0",
|
|
|
|
|
id);
|
2006-05-04 22:07:30 +00:00
|
|
|
REGISTER_NODE_METHODS(ob_sd, nodebuff);
|
2006-05-06 21:33:36 +00:00
|
|
|
if (esp->sd[id].media == TYPE_ROM) {
|
2006-05-04 22:07:30 +00:00
|
|
|
counter_ptr = &cdcount;
|
|
|
|
|
} else {
|
|
|
|
|
counter_ptr = &diskcount;
|
|
|
|
|
}
|
|
|
|
|
if (*counter_ptr == 0) {
|
2009-01-06 20:27:01 +00:00
|
|
|
add_alias(nodebuff, esp->sd[id].media_str[0]);
|
|
|
|
|
add_alias(nodebuff, esp->sd[id].media_str[1]);
|
2006-05-04 22:07:30 +00:00
|
|
|
}
|
2009-01-06 20:27:01 +00:00
|
|
|
snprintf(aliasbuff, sizeof(aliasbuff), "%s%d",
|
|
|
|
|
esp->sd[id].media_str[0], *counter_ptr);
|
|
|
|
|
add_alias(nodebuff, aliasbuff);
|
|
|
|
|
snprintf(aliasbuff, sizeof(aliasbuff), "%s%d",
|
|
|
|
|
esp->sd[id].media_str[1], *counter_ptr);
|
2006-05-04 22:07:30 +00:00
|
|
|
add_alias(nodebuff, aliasbuff);
|
2008-11-30 13:44:38 +00:00
|
|
|
snprintf(aliasbuff, sizeof(aliasbuff), "sd(0,%d,0)", id);
|
2006-05-16 17:36:09 +00:00
|
|
|
add_alias(nodebuff, aliasbuff);
|
2008-11-30 13:44:38 +00:00
|
|
|
snprintf(aliasbuff, sizeof(aliasbuff), "sd(0,%d,0)@0,0", id);
|
2006-06-05 20:02:44 +00:00
|
|
|
add_alias(nodebuff, aliasbuff);
|
2006-05-16 17:36:09 +00:00
|
|
|
(*counter_ptr)++;
|
2006-05-04 22:07:30 +00:00
|
|
|
}
|
2006-05-16 17:36:09 +00:00
|
|
|
DPRINTF("done\n");
|
2006-05-04 22:07:30 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|