2004-04-15 00:24:50 +02:00
# include <stdio.h>
2007-04-11 20:44:42 +02:00
# include <stdlib.h>
# include "pirq_routing.h"
2004-04-15 00:24:50 +02:00
static char * preamble [ ] = {
2009-05-22 20:17:06 +02:00
" /* \n " ,
" * This file is part of the coreboot project. \n " ,
" * \n " ,
" * Copyright (C) 200x TODO <TODO@TODO> \n " ,
" * \n " ,
" * This program is free software; you can redistribute it and/or modify \n " ,
" * it under the terms of the GNU General Public License as published by \n " ,
" * the Free Software Foundation; either version 2 of the License, or \n " ,
" * (at your option) any later version. \n " ,
2004-04-15 00:24:50 +02:00
" * \n " ,
2009-05-22 20:17:06 +02:00
" * This program is distributed in the hope that it will be useful, \n " ,
" * but WITHOUT ANY WARRANTY; without even the implied warranty of \n " ,
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n " ,
" * GNU General Public License for more details. \n " ,
2007-04-21 20:17:50 +02:00
" * \n " ,
2009-05-22 20:17:06 +02:00
" * You should have received a copy of the GNU General Public License \n " ,
" * along with this program; if not, write to the Free Software \n " ,
" * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA \n " ,
" */ \n \n " ,
" #ifdef GETPIR /* TODO: Drop this when copying to coreboot. */ \n " ,
" #include \" pirq_routing.h \" /* TODO: Drop this when copying to coreboot. */ \n " ,
" #else /* TODO: Drop this when copying to coreboot. */ \n "
2007-04-11 20:44:42 +02:00
" #include <arch/pirq_routing.h> \n " ,
2009-05-22 20:17:06 +02:00
" #endif /* TODO: Drop this when copying to coreboot. */ \n \n "
2004-04-15 00:24:50 +02:00
" const struct irq_routing_table intel_irq_routing_table = { \n " ,
2009-05-22 20:17:06 +02:00
" \t PIRQ_SIGNATURE, /* u32 signature */ \n " ,
" \t PIRQ_VERSION, /* u16 version */ \n " ,
2004-04-15 00:24:50 +02:00
0
} ;
2004-09-07 23:31:06 +02:00
void code_gen ( char * filename , struct irq_routing_table * rt )
2004-04-15 00:24:50 +02:00
{
char * * code = preamble ;
struct irq_info * se_arr = ( struct irq_info * ) ( ( char * ) rt + 32 ) ;
int i , ts = ( rt - > size - 32 ) / 16 ;
2004-09-07 23:31:06 +02:00
FILE * fpir ;
if ( ( fpir = fopen ( filename , " w " ) ) = = NULL ) {
printf ( " Failed creating file! \n " ) ;
exit ( 2 ) ;
}
2004-04-15 00:24:50 +02:00
while ( * code )
fprintf ( fpir , " %s " , * code + + ) ;
2009-05-22 20:17:06 +02:00
fprintf ( fpir , " \t 32 + 16 * %d, /* Max. number of devices on the bus */ \n " ,
2004-04-15 00:24:50 +02:00
ts , ts ) ;
2009-05-22 20:17:06 +02:00
fprintf ( fpir , " \t 0x%02x, /* Interrupt router bus */ \n " ,
2004-04-15 00:24:50 +02:00
rt - > rtr_bus ) ;
2009-05-22 20:17:06 +02:00
fprintf ( fpir , " \t (0x%02x << 3) | 0x%01x, /* Interrupt router dev */ \n " ,
2004-04-15 00:24:50 +02:00
rt - > rtr_devfn > > 3 , rt - > rtr_devfn & 7 ) ;
2009-05-22 20:17:06 +02:00
fprintf ( fpir , " \t %#x, /* IRQs devoted exclusively to PCI usage */ \n " ,
2004-04-15 00:24:50 +02:00
rt - > exclusive_irqs ) ;
2009-05-22 20:17:06 +02:00
fprintf ( fpir , " \t %#x, /* Vendor */ \n " , rt - > rtr_vendor ) ;
fprintf ( fpir , " \t %#x, /* Device */ \n " , rt - > rtr_device ) ;
fprintf ( fpir , " \t %#x, /* Miniport */ \n " ,
2004-04-15 00:24:50 +02:00
rt - > miniport_data ) ;
fprintf ( fpir , " \t { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* u8 rfu[11] */ \n " ) ;
2009-05-22 20:17:06 +02:00
fprintf ( fpir , " \t %#x, /* Checksum (has to be set to some value that \n * would give 0 after the sum of all bytes \n * for this structure (including checksum). \n */ \n " ,
2004-04-15 00:24:50 +02:00
rt - > checksum ) ;
fprintf ( fpir , " \t { \n " ) ;
2009-05-22 20:17:06 +02:00
fprintf ( fpir , " \t \t /* bus, dev | fn, {link, bitmap}, {link, bitmap}, {link, bitmap}, {link, bitmap}, slot, rfu */ \n " ) ;
2004-04-15 00:24:50 +02:00
for ( i = 0 ; i < ts ; i + + ) {
2009-05-22 20:17:06 +02:00
fprintf ( fpir , " \t \t {0x%02x, (0x%02x << 3) | 0x%01x, {{0x%02x, 0x%04x}, {0x%02x, 0x%04x}, {0x%02x, 0x%04x}, {0x%02x, 0x%04x}}, 0x%x, 0x%x}, \n " ,
2004-04-15 00:24:50 +02:00
( se_arr + i ) - > bus , ( se_arr + i ) - > devfn > > 3 ,
( se_arr + i ) - > devfn & 7 , ( se_arr + i ) - > irq [ 0 ] . link ,
( se_arr + i ) - > irq [ 0 ] . bitmap , ( se_arr + i ) - > irq [ 1 ] . link ,
( se_arr + i ) - > irq [ 1 ] . bitmap , ( se_arr + i ) - > irq [ 2 ] . link ,
( se_arr + i ) - > irq [ 2 ] . bitmap , ( se_arr + i ) - > irq [ 3 ] . link ,
( se_arr + i ) - > irq [ 3 ] . bitmap , ( se_arr + i ) - > slot ,
( se_arr + i ) - > rfu ) ;
}
fprintf ( fpir , " \t } \n " ) ;
fprintf ( fpir , " }; \n " ) ;
2004-09-07 23:31:06 +02:00
2008-03-25 20:43:01 +01:00
fprintf ( fpir , " \n unsigned long write_pirq_routing_table(unsigned long addr) \n " ) ;
fprintf ( fpir , " { \n " ) ;
fprintf ( fpir , " \t return copy_pirq_routing_table(addr); \n " ) ;
fprintf ( fpir , " } \n " ) ;
2004-09-07 23:31:06 +02:00
fclose ( fpir ) ;
2004-04-15 00:24:50 +02:00
}