device,nb/amd: Deduplicate add_more_links()

This function is duplicated in many AMD northbridge files, and all
the definitions have started to diverge somewhat. This moves a single
copy into device utils and deletes the rest. The function definition
from nb/amd/amdfam10 was chosen to be kept, since it contains several
fixes from commit 59d609217b (AMD fam10: Fix add_more_links) that
the others don't have.

For the ease of diffing, the checkpatch lints and other small cleanups
will be done in a follow-up patch.

Change-Id: I5ea73126092449db3f18e19ac0660439313072de
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/33237
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Jacob Garber 2019-06-05 16:32:28 -06:00 committed by Martin Roth
parent d10680bbbf
commit f77f7cdf89
8 changed files with 37 additions and 216 deletions

View File

@ -654,6 +654,42 @@ bool dev_is_active_bridge(struct device *dev)
return 0;
}
void add_more_links(struct device *dev, unsigned total_links)
{
struct bus *link, *last = NULL;
int link_num = -1;
for (link = dev->link_list; link; link = link->next) {
if (link_num < link->link_num)
link_num = link->link_num;
last = link;
}
if (last) {
int links = total_links - (link_num + 1);
if (links > 0) {
link = malloc(links*sizeof(*link));
if (!link)
die("Couldn't allocate more links!\n");
memset(link, 0, links*sizeof(*link));
last->next = link;
}
} else {
link = malloc(total_links*sizeof(*link));
memset(link, 0, total_links*sizeof(*link));
dev->link_list = link;
}
for (link_num = link_num + 1; link_num < total_links; link_num++) {
link->link_num = link_num;
link->dev = dev;
link->next = link + 1;
last = link;
link = link->next;
}
last->next = NULL;
}
static void resource_tree(const struct device *root, int debug_level, int depth)
{
int i = 0;

View File

@ -191,6 +191,7 @@ const char *bus_path(struct bus *bus);
void dev_set_enabled(struct device *dev, int enable);
void disable_children(struct bus *bus);
bool dev_is_active_bridge(struct device *dev);
void add_more_links(struct device *dev, unsigned total_links);
/* Option ROM helper functions */
void run_bios(struct device *dev, unsigned long addr);

View File

@ -772,42 +772,6 @@ static void sysconf_init(struct device *dev) // first node
node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
}
static void add_more_links(struct device *dev, unsigned int total_links)
{
struct bus *link, *last = NULL;
int link_num;
for (link = dev->link_list; link; link = link->next)
last = link;
if (last) {
int links = total_links - last->link_num;
link_num = last->link_num;
if (links > 0) {
link = malloc(links*sizeof(*link));
if (!link)
die("Couldn't allocate more links!\n");
memset(link, 0, links*sizeof(*link));
last->next = link;
}
}
else {
link_num = -1;
link = malloc(total_links*sizeof(*link));
memset(link, 0, total_links*sizeof(*link));
dev->link_list = link;
}
for (link_num = link_num + 1; link_num < total_links; link_num++) {
link->link_num = link_num;
link->dev = dev;
link->next = link + 1;
last = link;
link = link->next;
}
last->next = NULL;
}
static void cpu_bus_scan(struct device *dev)
{
struct bus *cpu_bus;

View File

@ -798,42 +798,6 @@ static void sysconf_init(struct device *dev) // first node
node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
}
static void add_more_links(struct device *dev, unsigned int total_links)
{
struct bus *link, *last = NULL;
int link_num;
for (link = dev->link_list; link; link = link->next)
last = link;
if (last) {
int links = total_links - last->link_num;
link_num = last->link_num;
if (links > 0) {
link = malloc(links*sizeof(*link));
if (!link)
die("Couldn't allocate more links!\n");
memset(link, 0, links*sizeof(*link));
last->next = link;
}
}
else {
link_num = -1;
link = malloc(total_links*sizeof(*link));
memset(link, 0, total_links*sizeof(*link));
dev->link_list = link;
}
for (link_num = link_num + 1; link_num < total_links; link_num++) {
link->link_num = link_num;
link->dev = dev;
link->next = link + 1;
last = link;
link = link->next;
}
last->next = NULL;
}
static void cpu_bus_scan(struct device *dev)
{
struct bus *cpu_bus;

View File

@ -1361,42 +1361,6 @@ static void sysconf_init(struct device *dev) // first node
#endif
}
static void add_more_links(struct device *dev, unsigned total_links)
{
struct bus *link, *last = NULL;
int link_num = -1;
for (link = dev->link_list; link; link = link->next) {
if (link_num < link->link_num)
link_num = link->link_num;
last = link;
}
if (last) {
int links = total_links - (link_num + 1);
if (links > 0) {
link = malloc(links*sizeof(*link));
if (!link)
die("Couldn't allocate more links!\n");
memset(link, 0, links*sizeof(*link));
last->next = link;
}
} else {
link = malloc(total_links*sizeof(*link));
memset(link, 0, total_links*sizeof(*link));
dev->link_list = link;
}
for (link_num = link_num + 1; link_num < total_links; link_num++) {
link->link_num = link_num;
link->dev = dev;
link->next = link + 1;
last = link;
link = link->next;
}
last->next = NULL;
}
static void remap_bsp_lapic(struct bus *cpu_bus)
{
struct device_path cpu_path;

View File

@ -786,42 +786,6 @@ static void sysconf_init(struct device *dev) // first node
node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
}
static void add_more_links(struct device *dev, unsigned total_links)
{
struct bus *link, *last = NULL;
int link_num;
for (link = dev->link_list; link; link = link->next)
last = link;
if (last) {
int links = total_links - last->link_num;
link_num = last->link_num;
if (links > 0) {
link = malloc(links*sizeof(*link));
if (!link)
die("Couldn't allocate more links!\n");
memset(link, 0, links*sizeof(*link));
last->next = link;
}
}
else {
link_num = -1;
link = malloc(total_links*sizeof(*link));
memset(link, 0, total_links*sizeof(*link));
dev->link_list = link;
}
for (link_num = link_num + 1; link_num < total_links; link_num++) {
link->link_num = link_num;
link->dev = dev;
link->next = link + 1;
last = link;
link = link->next;
}
last->next = NULL;
}
static void cpu_bus_scan(struct device *dev)
{
struct bus *cpu_bus;

View File

@ -784,42 +784,6 @@ static void sysconf_init(struct device *dev) // first node
node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; // NodeCnt[2:0]
}
static void add_more_links(struct device *dev, unsigned total_links)
{
struct bus *link, *last = NULL;
int link_num;
for (link = dev->link_list; link; link = link->next)
last = link;
if (last) {
int links = total_links - last->link_num;
link_num = last->link_num;
if (links > 0) {
link = malloc(links*sizeof(*link));
if (!link)
die("Couldn't allocate more links!\n");
memset(link, 0, links*sizeof(*link));
last->next = link;
}
}
else {
link_num = -1;
link = malloc(total_links*sizeof(*link));
memset(link, 0, total_links*sizeof(*link));
dev->link_list = link;
}
for (link_num = link_num + 1; link_num < total_links; link_num++) {
link->link_num = link_num;
link->dev = dev;
link->next = link + 1;
last = link;
link = link->next;
}
last->next = NULL;
}
static void cpu_bus_scan(struct device *dev)
{
struct bus *cpu_bus;

View File

@ -1025,42 +1025,6 @@ static void sysconf_init(struct device *dev) // first node
node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
}
static void add_more_links(struct device *dev, unsigned int total_links)
{
struct bus *link, *last = NULL;
int link_num;
for (link = dev->link_list; link; link = link->next)
last = link;
if (last) {
int links = total_links - last->link_num;
link_num = last->link_num;
if (links > 0) {
link = malloc(links*sizeof(*link));
if (!link)
die("Couldn't allocate more links!\n");
memset(link, 0, links*sizeof(*link));
last->next = link;
}
}
else {
link_num = -1;
link = malloc(total_links*sizeof(*link));
memset(link, 0, total_links*sizeof(*link));
dev->link_list = link;
}
for (link_num = link_num + 1; link_num < total_links; link_num++) {
link->link_num = link_num;
link->dev = dev;
link->next = link + 1;
last = link;
link = link->next;
}
last->next = NULL;
}
static void cpu_bus_scan(struct device *dev)
{
struct bus *cpu_bus;