SMBus on CS5536 support
This commit is contained in:
parent
d9f31a41ca
commit
232f7e29c9
6 changed files with 419 additions and 1 deletions
213
bus/cs5536.c
Normal file
213
bus/cs5536.c
Normal file
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/cs5536.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/time.h>
|
||||
|
||||
int
|
||||
grub_cs5536_find (grub_pci_device_t *devp)
|
||||
{
|
||||
int found = 0;
|
||||
auto int NESTED_FUNC_ATTR hook (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid);
|
||||
|
||||
int NESTED_FUNC_ATTR hook (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid)
|
||||
{
|
||||
if (pciid == GRUB_CS5536_PCIID)
|
||||
{
|
||||
*devp = dev;
|
||||
found = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_pci_iterate (hook);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
grub_uint64_t
|
||||
grub_cs5536_read_msr (grub_pci_device_t dev, grub_uint32_t addr)
|
||||
{
|
||||
grub_uint64_t ret = 0;
|
||||
grub_pci_write (grub_pci_make_address (dev, GRUB_CS5536_MSR_MAILBOX_ADDR),
|
||||
addr);
|
||||
ret = (grub_uint64_t)
|
||||
grub_pci_read (grub_pci_make_address (dev, GRUB_CS5536_MSR_MAILBOX_DATA0));
|
||||
ret |= (((grub_uint64_t)
|
||||
grub_pci_read (grub_pci_make_address (dev,
|
||||
GRUB_CS5536_MSR_MAILBOX_DATA1)))
|
||||
<< 32);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
grub_cs5536_write_msr (grub_pci_device_t dev, grub_uint32_t addr,
|
||||
grub_uint64_t val)
|
||||
{
|
||||
grub_pci_write (grub_pci_make_address (dev, GRUB_CS5536_MSR_MAILBOX_ADDR),
|
||||
addr);
|
||||
grub_pci_write (grub_pci_make_address (dev, GRUB_CS5536_MSR_MAILBOX_DATA0),
|
||||
val & 0xffffffff);
|
||||
grub_pci_write (grub_pci_make_address (dev, GRUB_CS5536_MSR_MAILBOX_DATA1),
|
||||
val >> 32);
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_cs5536_smbus_wait (grub_port_t smbbase)
|
||||
{
|
||||
grub_uint64_t start = grub_get_time_ms ();
|
||||
while (1)
|
||||
{
|
||||
grub_uint8_t status;
|
||||
status = grub_inb (smbbase + GRUB_CS5536_SMB_REG_STATUS);
|
||||
if (status & (1 << 6))
|
||||
return GRUB_ERR_NONE;
|
||||
if (status & (1 << 5))
|
||||
return grub_error (GRUB_ERR_IO, "SM bus error");
|
||||
if (status & (1 << 4))
|
||||
return grub_error (GRUB_ERR_IO, "NACK received");
|
||||
if (grub_get_time_ms () > start + 40)
|
||||
return grub_error (GRUB_ERR_IO, "SM stalled");
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_cs5536_read_spd_byte (grub_port_t smbbase, grub_uint8_t dev,
|
||||
grub_uint8_t addr, grub_uint8_t *res)
|
||||
{
|
||||
grub_err_t err;
|
||||
|
||||
/* Send START. */
|
||||
grub_outb (grub_inb (smbbase + GRUB_CS5536_SMB_REG_CTRL1)
|
||||
| GRUB_CS5536_SMB_REG_CTRL1_START,
|
||||
smbbase + GRUB_CS5536_SMB_REG_CTRL1);
|
||||
|
||||
/* Send device address. */
|
||||
err = grub_cs5536_smbus_wait (smbbase);
|
||||
if (err)
|
||||
return err;
|
||||
grub_outb (dev << 1, smbbase + GRUB_CS5536_SMB_REG_DATA);
|
||||
|
||||
/* Send ACK. */
|
||||
err = grub_cs5536_smbus_wait (smbbase);
|
||||
if (err)
|
||||
return err;
|
||||
grub_outb (grub_inb (smbbase + GRUB_CS5536_SMB_REG_CTRL1)
|
||||
| GRUB_CS5536_SMB_REG_CTRL1_ACK,
|
||||
smbbase + GRUB_CS5536_SMB_REG_CTRL1);
|
||||
|
||||
/* Send byte address. */
|
||||
grub_outb (addr, smbbase + GRUB_CS5536_SMB_REG_DATA);
|
||||
|
||||
/* Send START. */
|
||||
err = grub_cs5536_smbus_wait (smbbase);
|
||||
if (err)
|
||||
return err;
|
||||
grub_outb (grub_inb (smbbase + GRUB_CS5536_SMB_REG_CTRL1)
|
||||
| GRUB_CS5536_SMB_REG_CTRL1_START,
|
||||
smbbase + GRUB_CS5536_SMB_REG_CTRL1);
|
||||
|
||||
/* Send device address. */
|
||||
err = grub_cs5536_smbus_wait (smbbase);
|
||||
if (err)
|
||||
return err;
|
||||
grub_outb ((dev << 1) | 1, smbbase + GRUB_CS5536_SMB_REG_DATA);
|
||||
|
||||
/* Send STOP. */
|
||||
err = grub_cs5536_smbus_wait (smbbase);
|
||||
if (err)
|
||||
return err;
|
||||
grub_outb (grub_inb (smbbase + GRUB_CS5536_SMB_REG_CTRL1)
|
||||
| GRUB_CS5536_SMB_REG_CTRL1_STOP,
|
||||
smbbase + GRUB_CS5536_SMB_REG_CTRL1);
|
||||
|
||||
err = grub_cs5536_smbus_wait (smbbase);
|
||||
if (err)
|
||||
return err;
|
||||
*res = grub_inb (smbbase + GRUB_CS5536_SMB_REG_DATA);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_cs5536_init_smbus (grub_pci_device_t dev, grub_uint16_t divisor,
|
||||
grub_port_t *smbbase)
|
||||
{
|
||||
grub_uint64_t smbbar;
|
||||
|
||||
smbbar = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_SMB_BAR);
|
||||
|
||||
/* FIXME */
|
||||
if (!(smbbar & GRUB_CS5536_LBAR_ENABLE))
|
||||
return grub_error(GRUB_ERR_IO, "SMB controller not enabled\n");
|
||||
*smbbase = (smbbar & GRUB_CS5536_LBAR_ADDR_MASK) + GRUB_MACHINE_PCI_IO_BASE;
|
||||
|
||||
if (divisor < 8)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid divisor");
|
||||
|
||||
/* Disable SMB. */
|
||||
grub_outb (0, *smbbase + GRUB_CS5536_SMB_REG_CTRL2);
|
||||
|
||||
/* Disable interrupts. */
|
||||
grub_outb (0, *smbbase + GRUB_CS5536_SMB_REG_CTRL1);
|
||||
|
||||
/* Set as master. */
|
||||
grub_outb (GRUB_CS5536_SMB_REG_ADDR_MASTER,
|
||||
*smbbase + GRUB_CS5536_SMB_REG_ADDR);
|
||||
|
||||
/* Launch. */
|
||||
grub_outb (((divisor >> 7) & 0xff), *smbbase + GRUB_CS5536_SMB_REG_CTRL3);
|
||||
grub_outb (((divisor << 1) & 0xfe) | GRUB_CS5536_SMB_REG_CTRL2_ENABLE,
|
||||
*smbbase + GRUB_CS5536_SMB_REG_CTRL2);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_cs5536_read_spd (grub_port_t smbbase, grub_uint8_t dev,
|
||||
struct grub_smbus_spd *res)
|
||||
{
|
||||
grub_err_t err;
|
||||
grub_size_t size;
|
||||
grub_uint8_t b;
|
||||
grub_size_t ptr;
|
||||
|
||||
err = grub_cs5536_read_spd_byte (smbbase, dev, 0, &b);
|
||||
if (err)
|
||||
return err;
|
||||
if (b == 0)
|
||||
return grub_error (GRUB_ERR_IO, "no SPD found");
|
||||
size = b;
|
||||
|
||||
((grub_uint8_t *) res)[0] = b;
|
||||
for (ptr = 1; ptr < size; ptr++)
|
||||
{
|
||||
err = grub_cs5536_read_spd_byte (smbbase, dev, ptr,
|
||||
&((grub_uint8_t *) res)[ptr]);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
92
commands/mips/yeeloong/lsspd.c
Normal file
92
commands/mips/yeeloong/lsspd.c
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/cs5536.h>
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_lsspd (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
{
|
||||
grub_pci_device_t dev;
|
||||
grub_port_t smbbase;
|
||||
int i;
|
||||
grub_err_t err;
|
||||
|
||||
if (!grub_cs5536_find (&dev))
|
||||
{
|
||||
grub_printf ("No CS5536 found\n");
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
grub_printf ("CS5536 at %d:%d.%d\n", grub_pci_get_bus (dev),
|
||||
grub_pci_get_device (dev), grub_pci_get_function (dev));
|
||||
|
||||
err = grub_cs5536_init_smbus (dev, 0x7fff, &smbbase);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_printf ("SMB base = 0x%x\n", smbbase);
|
||||
|
||||
for (i = GRUB_SMB_RAM_START_ADDR;
|
||||
i < GRUB_SMB_RAM_START_ADDR + GRUB_SMB_RAM_NUM_MAX; i++)
|
||||
{
|
||||
struct grub_smbus_spd spd;
|
||||
grub_memset (&spd, 0, sizeof (spd));
|
||||
grub_printf ("Device %d\n", i);
|
||||
err = grub_cs5536_read_spd (smbbase, i, &spd);
|
||||
if (err)
|
||||
{
|
||||
grub_print_error ();
|
||||
continue;
|
||||
}
|
||||
grub_printf ("Written SPD bytes: %d B.\n", spd.written_size);
|
||||
grub_printf ("Total flash size: %d B.\n", 1 << spd.log_total_flash_size);
|
||||
if (spd.memory_type == GRUB_SMBUS_SPD_MEMORY_TYPE_DDR2)
|
||||
{
|
||||
char str[sizeof (spd.ddr2.part_number) + 1];
|
||||
grub_printf ("Memory type: DDR2.\n");
|
||||
grub_memcpy (str, spd.ddr2.part_number,
|
||||
sizeof (spd.ddr2.part_number));
|
||||
str[sizeof (spd.ddr2.part_number)] = 0;
|
||||
grub_printf ("Part no: %s.\n", str);
|
||||
}
|
||||
else
|
||||
grub_printf ("Memory type: Unknown.\n");
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
|
||||
GRUB_MOD_INIT(lsspd)
|
||||
{
|
||||
cmd = grub_register_command ("lsspd", grub_cmd_lsspd, 0,
|
||||
"Print Memory information.");
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(lsspd)
|
||||
{
|
||||
grub_unregister_command (cmd);
|
||||
}
|
|
@ -73,6 +73,17 @@ datehook_mod_SOURCES = hook/datehook.c
|
|||
datehook_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||
|
||||
# For lsspd.mod
|
||||
pkglib_MODULES += lsspd.mod
|
||||
lsspd_mod_SOURCES = commands/mips/yeeloong/lsspd.c
|
||||
lsspd_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
lsspd_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||
|
||||
# For cs5536.mod
|
||||
pkglib_MODULES += cs5536.mod
|
||||
cs5536_mod_SOURCES = bus/cs5536.c
|
||||
cs5536_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
cs5536_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||
|
||||
sbin_SCRIPTS += grub-install
|
||||
grub_install_SOURCES = util/grub-install.in
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <grub/time.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/scsi.h>
|
||||
#include <grub/cs5536.h>
|
||||
|
||||
/* At the moment, only two IDE ports are supported. */
|
||||
static const grub_port_t grub_ata_ioaddress[] = { 0x1f0, 0x170 };
|
||||
|
@ -408,7 +409,7 @@ grub_ata_pciinit (grub_pci_device_t dev,
|
|||
class = grub_pci_read (addr);
|
||||
|
||||
/* AMD CS5536 Southbridge. */
|
||||
if (pciid == 0x208f1022)
|
||||
if (pciid == GRUB_CS5536_PCIID)
|
||||
{
|
||||
cs5536 = 1;
|
||||
nports = 1;
|
||||
|
|
62
include/grub/cs5536.h
Normal file
62
include/grub/cs5536.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_CS5536_HEADER
|
||||
#define GRUB_CS5536_HEADER 1
|
||||
|
||||
#include <grub/pci.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/smbus.h>
|
||||
|
||||
#define GRUB_CS5536_PCIID 0x208f1022
|
||||
#define GRUB_CS5536_MSR_MAILBOX_ADDR 0xf4
|
||||
#define GRUB_CS5536_MSR_MAILBOX_DATA0 0xf8
|
||||
#define GRUB_CS5536_MSR_MAILBOX_DATA1 0xfc
|
||||
#define GRUB_CS5536_MSR_SMB_BAR 0x8000000b
|
||||
#define GRUB_CS5536_SMB_REG_DATA 0x0
|
||||
#define GRUB_CS5536_SMB_REG_STATUS 0x1
|
||||
#define GRUB_CS5536_SMB_REG_CTRL1 0x3
|
||||
#define GRUB_CS5536_SMB_REG_CTRL1_START 0x01
|
||||
#define GRUB_CS5536_SMB_REG_CTRL1_STOP 0x02
|
||||
#define GRUB_CS5536_SMB_REG_CTRL1_ACK 0x10
|
||||
#define GRUB_CS5536_SMB_REG_ADDR 0x4
|
||||
#define GRUB_CS5536_SMB_REG_ADDR_MASTER 0x0
|
||||
#define GRUB_CS5536_SMB_REG_CTRL2 0x5
|
||||
#define GRUB_CS5536_SMB_REG_CTRL2_ENABLE 0x1
|
||||
#define GRUB_CS5536_SMB_REG_CTRL3 0x6
|
||||
|
||||
#define GRUB_CS5536_LBAR_ADDR_MASK 0x000000000000fff8ULL
|
||||
#define GRUB_CS5536_LBAR_ADDR_OFF 3
|
||||
#define GRUB_CS5536_LBAR_ENABLE 0x0000000100000000ULL
|
||||
#define GRUB_SMB_RAM_START_ADDR 0x50
|
||||
#define GRUB_SMB_RAM_NUM_MAX 0x08
|
||||
|
||||
int grub_cs5536_find (grub_pci_device_t *devp);
|
||||
|
||||
grub_uint64_t grub_cs5536_read_msr (grub_pci_device_t dev, grub_uint32_t addr);
|
||||
void grub_cs5536_write_msr (grub_pci_device_t dev, grub_uint32_t addr,
|
||||
grub_uint64_t val);
|
||||
grub_err_t grub_cs5536_read_spd_byte (grub_port_t smbbase, grub_uint8_t dev,
|
||||
grub_uint8_t addr, grub_uint8_t *res);
|
||||
grub_err_t grub_cs5536_read_spd (grub_port_t smbbase, grub_uint8_t dev,
|
||||
struct grub_smbus_spd *res);
|
||||
grub_err_t grub_cs5536_smbus_wait (grub_port_t smbbase);
|
||||
grub_err_t grub_cs5536_init_smbus (grub_pci_device_t dev, grub_uint16_t divisor,
|
||||
grub_port_t *smbbase);
|
||||
|
||||
#endif
|
39
include/grub/smbus.h
Normal file
39
include/grub/smbus.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_SMBUS_HEADER
|
||||
#define GRUB_SMBUS_HEADER 1
|
||||
|
||||
struct grub_smbus_spd
|
||||
{
|
||||
grub_uint8_t written_size;
|
||||
grub_uint8_t log_total_flash_size;
|
||||
#define GRUB_SMBUS_SPD_MEMORY_TYPE_DDR2 8
|
||||
grub_uint8_t memory_type;
|
||||
union
|
||||
{
|
||||
grub_uint8_t unknown[253];
|
||||
struct {
|
||||
grub_uint8_t unused1[70];
|
||||
grub_uint8_t part_number[18];
|
||||
grub_uint8_t unused2[165];
|
||||
} ddr2;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue