示例#1
0
/* php_spintf_appenduint() {{{ */
inline static void
php_sprintf_appenduint(char **buffer, int *pos, int *size,
					   unsigned long number,
					   int width, char padding, int alignment)
{
	char numbuf[NUM_BUF_SIZE];
	register unsigned long magn, nmagn;
	register unsigned int i = NUM_BUF_SIZE - 1;

	PRINTF_DEBUG(("sprintf: appenduint(%x, %x, %x, %d, %d, '%c', %d)\n",
				  *buffer, pos, size, number, width, padding, alignment));
	magn = (unsigned long) number;

	/* Can't right-pad 0's on integers */
	if (alignment == 0 && padding == '0') padding = ' ';

	numbuf[i] = '\0';

	do {
		nmagn = magn / 10;

		numbuf[--i] = (unsigned char)(magn - (nmagn * 10)) + '0';
		magn = nmagn;
	} while (magn > 0 && i > 0);

	PRINTF_DEBUG(("sprintf: appending %d as \"%s\", i=%d\n", number, &numbuf[i], i));
	php_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0,
							 padding, alignment, (NUM_BUF_SIZE - 1) - i, 0, 0, 0);
}
示例#2
0
文件: netdrv.c 项目: ariavie/bcm
void
rx_pkt_thread(void *param)
{
    int unit = (int) param;
    struct _rxctrl *prx_control = bcm_get_rx_control_ptr(unit);
    bcm_pkt_t pPkt;

    PRINTF_DEBUG(("RX:  Packet thread starting\n"));

    /* Sleep on sem */
    while (1) {
        rx_thread_dv_check(unit);

        prx_control->pkt_notify_given = FALSE;

        /* Service as many packets as possible */
        while (!RXQ_EMPTY(&g_rxq_ctrl)) {
            RXQ_DEQUEUE(&g_rxq_ctrl, &pPkt);
            NetdrvSendToEnd(&pPkt);
        }

        sal_sem_take(prx_control->pkt_notify, sal_sem_FOREVER);
    }

    prx_control->thread_exit_complete = TRUE;
    PRINTF_DEBUG(("RX: Packet thread exitting\n"));
    sal_thread_exit(0);

    return;
}
示例#3
0
/* php_spintf_appendd2n() {{{ */
inline static void
php_sprintf_append2n(char **buffer, int *pos, int *size, long number,
					 int width, char padding, int alignment, int n,
					 char *chartable, int expprec)
{
	char numbuf[NUM_BUF_SIZE];
	register unsigned long num;
	register unsigned int  i = NUM_BUF_SIZE - 1;
	register int andbits = (1 << n) - 1;

	PRINTF_DEBUG(("sprintf: append2n(%x, %x, %x, %d, %d, '%c', %d, %d, %x)\n",
				  *buffer, pos, size, number, width, padding, alignment, n,
				  chartable));
	PRINTF_DEBUG(("sprintf: append2n 2^%d andbits=%x\n", n, andbits));

	num = (unsigned long) number;
	numbuf[i] = '\0';

	do {
		numbuf[--i] = chartable[(num & andbits)];
		num >>= n;
	}
	while (num > 0);

	php_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0,
							 padding, alignment, (NUM_BUF_SIZE - 1) - i,
							 0, expprec, 0);
}
示例#4
0
/* php_spintf_appendstring() {{{ */
inline static void
php_sprintf_appendstring(char **buffer, int *pos, int *size, char *add,
						   int min_width, int max_width, char padding,
						   int alignment, int len, int neg, int expprec, int always_sign)
{
	register int npad;
	int req_size;
	int copy_len;
	int m_width;

	copy_len = (expprec ? MIN(max_width, len) : len);
	npad = min_width - copy_len;

	if (npad < 0) {
		npad = 0;
	}
	
	PRINTF_DEBUG(("sprintf: appendstring(%x, %d, %d, \"%s\", %d, '%c', %d)\n",
				  *buffer, *pos, *size, add, min_width, padding, alignment));
	m_width = MAX(min_width, copy_len);

	if(m_width > INT_MAX - *pos - 1) {
		zend_error_noreturn(E_ERROR, "Field width %d is too long", m_width);
	}

	req_size = *pos + m_width + 1;

	if (req_size > *size) {
		while (req_size > *size) {
			if(*size > INT_MAX/2) {
				zend_error_noreturn(E_ERROR, "Field width %d is too long", req_size); 
			}
			*size <<= 1;
		}
		PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", *size));
		*buffer = erealloc(*buffer, *size);
	}
	if (alignment == ALIGN_RIGHT) {
		if ((neg || always_sign) && padding=='0') {
			(*buffer)[(*pos)++] = (neg) ? '-' : '+';
			add++;
			len--;
			copy_len--;
		}
		while (npad-- > 0) {
			(*buffer)[(*pos)++] = padding;
		}
	}
	PRINTF_DEBUG(("sprintf: appending \"%s\"\n", add));
	memcpy(&(*buffer)[*pos], add, copy_len + 1);
	*pos += copy_len;
	if (alignment == ALIGN_LEFT) {
		while (npad--) {
			(*buffer)[(*pos)++] = padding;
		}
	}
}
示例#5
0
/* php_spintf_appendchar() {{{ */
inline static void
php_sprintf_appendchar(char **buffer, int *pos, int *size, char add TSRMLS_DC)
{
	if ((*pos + 1) >= *size) {
		*size <<= 1;
		PRINTF_DEBUG(("%s(): ereallocing buffer to %d bytes\n", get_active_function_name(TSRMLS_C), *size));
		*buffer = erealloc(*buffer, *size);
	}
	PRINTF_DEBUG(("sprintf: appending '%c', pos=\n", add, *pos));
	(*buffer)[(*pos)++] = add;
}
示例#6
0
/*
 * sb_hpet_cfg :
 * config the HPET module
 */
void sb_hpet_cfg(void)
{
	u8 rev = get_sb600_revision();
	pcitag_t sm_dev = _pci_make_tag(0, 20, 0);

	PRINTF_DEBUG();
#ifdef	CFG_ATI_HPET_BASE
#if	CFG_ATI_HPET_BASE
	if(ati_sb_cfg.hpet_en == SB_ENABLE){
		if(rev >= REV_SB600_A21){
			set_pm_enable_bits(0x55, 1 << 7, 0 << 7);
		}
		ati_sb_cfg.hpet_base = CFG_ATI_HPET_BASE;
		_pci_conf_write(sm_dev, 0x14, ati_sb_cfg.hpet_base);
		set_sbcfg_enable_bits(sm_dev, 0x64, 1 << 10, 1 << 10);
	}
#endif
#endif

	if(rev >= REV_SB600_A21){
		set_pm_enable_bits(0x55, 1 << 7, 1 << 7);
		set_pm_enable_bits(0x52, 1 << 6, 1 << 6);
	}

	return;
}
示例#7
0
文件: netdrv.c 项目: ariavie/bcm
void
DrvPollRcvPktTask(END_DEVICE *pDrvCtrl)
{
    uint32 stat = 0;
    uint32 rxmask = DS_DESC_DONE_TST(DRV_RX_DMA_CHAN) |
        DS_CHAIN_DONE_TST(DRV_RX_DMA_CHAN);
    uint32 txmask = DS_CHAIN_DONE_TST(0);
    int unit;
    int i = 0;

    PRINTF_DEBUG(("BCM NetDriver is starting polling mode.......\n"));

    for(;;) {
        for (unit = g_RxMinUnit; unit < _n_devices; unit++) {
            i++;
            stat = soc_pci_read(unit, CMIC_DMA_STAT);
            if ((stat & rxmask) != 0) {
                /* soc_dma_done_chain(unit, (uint32)0); */
                NetdrvHandleRcvPkt(pDrvCtrl, unit, stat);
            }

            rx_thread_dv_check(unit);
            if (i > 100) {
                taskDelay(1) ;
                i = 0;
            }
        }
    }
}
示例#8
0
void sb_last_c3_popup_setting(void)
{
	pcitag_t dev;
	u32 base, reg10;
	u8 type = get_sb600_platform();

	PRINTF_DEBUG();
	if(type == K8_ID){
		dev = _pci_make_tag(0, 20, 5);
		reg10 = _pci_conf_read(dev, 0x10);
		if( (reg10 != 0xffffffff) && (reg10 != 0x00) ){
			/* RPR8.3 K8 C3Pop-up for AC97, AC97_Memory_Mapped 0x80[1] = 1.
			 * If the CPU is K8, and C3PopUp function is enabled, then the BIOS should 
			 * set this mirror bit to inform the ac97 driver that C3Pop-up is enabled.
			 * The driver will in turn not set the SetBusBusy bit in Memory_Mapped 0x04[14]
			 */
			base = (reg10 & 0xfffffff0) | 0xA0000000;
			*(volatile u8 *)(base + 0x80) |= 1 << 1;
		}		
	}else{
		/* RPR2.4.2	C-State Function for the P4 platform
		 * Intel cpu C3 setting
		 * Smbus_PCI_config 0x64 [5] = 0 BmReq# is no longer used in P4 platform. Clear this bit 
		 * to disable the BmReq# input.
		 * Smbus_PCI_config 0x64 [4] = 1
		 */
		dev = _pci_make_tag(0, 20, 0);
		set_sbcfg_enable_bits(dev, 0x64, 1 << 5, 0 << 5);
		set_sbcfg_enable_bits(dev, 0x64, 1 << 4, 1 << 4);
	}

	return;
}
示例#9
0
文件: netdrv.c 项目: ariavie/bcm
LOCAL void
NetdrvConfig(END_DEVICE *pDrvCtrl)
{
    /* Set promiscuous mode if it's asked for. */

    if (END_FLAGS_GET(&pDrvCtrl->end) & IFF_PROMISC) {
        PRINTF_DEBUG(("\r\nSetting promiscuous mode on!"));
    } else {
        /*VOS_printf("\r\nSetting promiscuous mode off!");*/
    }

    /* Set up address filter for multicasting. */

    if (END_MULTI_LST_CNT(&pDrvCtrl->end) > 0) {
        NetdrvAddrFilterSet (pDrvCtrl);
    }

    

    

    

    return;
}
示例#10
0
void sb_last_sata_cache(void)
{
	u32 base;
	u32 val;
	pcitag_t sata_dev = _pci_make_tag(0, 0x12, 0);

	PRINTF_DEBUG();
	if(ati_sb_cfg.sata_cache_base){
		/* store sata base, size and signature */
		base = ati_sb_cfg.sata_cache_base | 0xa0000000;
		*(volatile u32 *)(base + 0x08) = ati_sb_cfg.sata_cache_base;
		*(volatile u32 *)(base + 0x04) = ati_sb_cfg.sata_cache_size;
		*(volatile u8 *)(base + 0x00) = 'A';
		*(volatile u8 *)(base + 0x01) = 'T';
		*(volatile u8 *)(base + 0x02) = 'i';
		*(volatile u8 *)(base + 0x03) = 'B';

		/* disable IO access */
		set_sbcfg_enable_bits(sata_dev, 0x04, 1 << 0, 0 << 0);

		/* reserved bit */
		set_sbcfg_enable_bits(sata_dev, 0x40, 1 << 20, 1 << 20);

		/* set cache base addr */
		val = _pci_conf_read(sata_dev, 0x10);
		val &= 0x00ffffff;
		val |= (ati_sb_cfg.sata_cache_base >> 24) << 24;
		_pci_conf_write(sata_dev, 0x10, val);
	}
示例#11
0
int atiKbRstWaCheck(void)
{
	u8 type = get_sb600_platform();

	PRINTF_DEBUG();
	/*enable keyboard reset only if not AMD systerm*/
	if(type == K8_ID)
		return disable_kb_rst_smi();
	else	
		return enable_kb_rst_smi();	
}
示例#12
0
int atiSbirqSmiCheck(void)
{
	u8 type = get_sb600_platform();

	PRINTF_DEBUG();
	if(type == K8_ID){
		set_pm_enable_bits(0x3, 1, 1);
		set_pm_enable_bits(0x6, 1, 1);
		return 0;
	}
	return 1;
}
示例#13
0
/*
 * satachannel_reset
 * detect and reset sata channel
 */
void sb_sata_channel_reset(void)
{
	PRINTF_DEBUG();
	if(ati_sb_cfg.sata_channel == SB_ENABLE){
		if( (ati_sb_cfg.sata_class == 0) 		/* native ide mode */
			|| (ati_sb_cfg.sata_class == 3)		/* legacy ide mode */
			|| (ati_sb_cfg.sata_class == 4) ){	/* ide->ahci mode*/
			sata_drive_detecting();
		}
	}

	return;
}
示例#14
0
void sb_last_p4_init(void)
{
	u8 type = get_sb600_platform();

	PRINTF_DEBUG();
	if(type == P4_ID){
		/* our platform is K8, there is no need yet : we should judge the CPU id for
		 * PBE support setting
		 */
	}

	return;
}
示例#15
0
文件: netdrv.c 项目: ariavie/bcm
int
NetdrvStart(END_DEVICE * pDrvCtrl)
{

#ifdef POLLING_MODE
    unsigned int unit;

   if (started == 1) { return OK; }
#endif

    /** start RX Tasks */
    PRINTF_DEBUG(("BCM NetDriver is starting .......\n"));

#ifdef POLLING_MODE
    if (_n_devices > MAX_DEVICES) {
        printf("\r\nCannot support switch chips over 4\r\n");
        return ERROR;
    }
#endif /* POLLING_MODE */

    __netDriver = pDrvCtrl;

    if (GetMacFromFlash(pDrvCtrl->enetAddr) == ERROR) {
        printf("Error: unable to start netdrv (Invalid MAC Address)\n");
        return ERROR;
    }

    bcopy ((char *)pDrvCtrl->enetAddr, 
           (char *)END_HADDR(&pDrvCtrl->end),
           END_HADDR_LEN(&pDrvCtrl->end));
    {
        extern void   bcmSystemInit();
        bcmSystemInit();
        taskDelay(100);
    }

    END_FLAGS_SET (&pDrvCtrl->end, IFF_UP | IFF_RUNNING);

#ifdef POLLING_MODE
    gPollRecvTaskId =
        taskSpawn("RxPollTask", 100, 0, 16384, (FUNCPTR)DrvPollRcvPktTask,
                   (int)pDrvCtrl, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    if (gPollRecvTaskId == ERROR) {
        return ERROR;
    }
    started = 1;
#endif /* POLLING_MODE */

    return (OK);
}
示例#16
0
文件: netdrv.c 项目: ariavie/bcm
LOCAL STATUS
NetdrvPollStart(END_DEVICE * pDrvCtrl)
{
    int  oldLevel;

    PRINTF_DEBUG(("\r\n  NetdrvPollStart STARTED"));

    oldLevel = intLock (); /* disable ints during update */

    pDrvCtrl->flags |= NETDRV_POLLING;

    intUnlock (oldLevel); /* now NetdrvInt won't get confused */

    NetdrvConfig (pDrvCtrl); /* reconfigure device */

    return (OK);
}
示例#17
0
文件: netdrv.c 项目: ariavie/bcm
LOCAL STATUS
NetdrvPollStop(END_DEVICE * pDrvCtrl)
{
    int  oldLevel;

    oldLevel = intLock (); /* disable ints during register updates */

    
    pDrvCtrl->flags &= ~NETDRV_POLLING;

    intUnlock(oldLevel);

    NetdrvConfig(pDrvCtrl);

    PRINTF_DEBUG(("\r\nNO POLLING"));

    return (OK);
}
示例#18
0
/* php_spintf_getnumber() {{{ */
inline static int
php_sprintf_getnumber(char *buffer, int *pos)
{
	char *endptr;
	register long num = strtol(&buffer[*pos], &endptr, 10);
	register int i = 0;

	if (endptr != NULL) {
		i = (endptr - &buffer[*pos]);
	}
	PRINTF_DEBUG(("sprintf_getnumber: number was %d bytes long\n", i));
	*pos += i;

	if (num >= INT_MAX || num < 0) {
		return -1;
	} else {
		return (int) num;
	}
}
示例#19
0
void sb_last_init_pci_autoclock_run(void)
{
	u32	val;
	pcitag_t dev = _pci_make_tag(0, 20, 4);

	PRINTF_DEBUG();
	_pci_conf_write(dev, 0x4C, ati_sb_cfg.clkrun_ctrl);

	val = _pci_conf_readn(dev, 0x50, 2);
	val &= 0x3F;
	val |= ati_sb_cfg.clkrun_ow << 6;
	_pci_conf_writen(dev, 0x50, val, 2);

	if(ati_sb_cfg.clkrun_ctrl == 1){
		set_sbcfg_enable_bits(dev, 0x64, 1 << 15, 1 << 15);
	}

	return;
}
示例#20
0
int atiP92WaCheck(void)
{
	pcitag_t sm_dev = _pci_make_tag(0, 20, 0);;
	u8 type = get_sb600_platform();

	PRINTF_DEBUG();
	DEBUG_INFO("p92_TRAP_BASE is %x\n", P92_TRAP_BASE);
	DEBUG_INFO("p92_TRAP_EN_REG is %x\n", P92_TRAP_EN_REG);
	/*enable keyboard reset only if not AMD systerm*/
	if(type == K8_ID){
		/* enable Port 92 trap on ProgramIoX*/	
		set_pm_enable_bits(P92_TRAP_BASE, 0xff, 0x92);
		set_pm_enable_bits(P92_TRAP_BASE + 1, 0xff, 0);
		set_pm_enable_bits(P92_TRAP_EN_REG, P92_TRAP_EN_BIT, P92_TRAP_EN_BIT);
		/*disable port 92 decoding*/
		set_sbcfg_enable_bits(sm_dev, 0x78, 1 << 14, 0);	
		/* set ACPI flag for port 92 trap*/
		ati_sb_cfg.p92t = P92_TRAP_ON_PIO;
		return 0; 
	} else	
		return 1;	
}
示例#21
0
static dv_t *
_tx_dv_alloc(int unit, int pkt_count, int dcb_count,
             bcm_pkt_cb_f chain_done_cb, void *cookie, int per_pkt_cb) 
{
    dv_t *dv;
    /* tx_dv_info_t *dv_info; */

    if (pkt_count > SOC_DV_PKTS_MAX) {
        PRINTF_DEBUG(("TX array:  Cannot TX more than %d pkts. "
            "Attempting %d.\n", SOC_DV_PKTS_MAX, pkt_count));
        return NULL;
    }

    if ((dv = soc_dma_dv_alloc(unit, DV_TX, dcb_count)) == NULL) {
        return NULL;
    }

    /* PRINTF_DEBUG(("=> %p %p\n", dv, dv_info)); */

    dv->dv_done_chain = _tx_dv_free;

    return dv;
}
示例#22
0
void sb_last_smi_service_check(void)
{
	int i = 0;
	struct ati_sb_smi *p = atiSbSmiPostTbl;
	struct ati_sb_smi *q = atiSbSmiRunTbl;

	PRINTF_DEBUG();
	while(1){
		if(p->service_routine == ~0)	
			return;
		if((u32)p->check_routine == ~0) {
			p++;
			continue;	
		}
		if(p->check_routine() == 0)
			return;	
		memcpy(q, q, sizeof(struct ati_sb_smi));	// copy a struct
		i++;
		if(i >= (RUNTBL_SIZE - 1))
			return;
		p++;
		q++;
	}
}
示例#23
0
void sb_last_sata_unconnected_shutdown_clock(void)
{
	u8 sata_class = ati_sb_cfg.sata_class;
	pcitag_t sata_dev = _pci_make_tag(0, 18, 0);
	u32 temp;

	PRINTF_DEBUG();
	if(ati_sb_cfg.sata_ck_au_off == SB_ENABLE){	// auto off
		if(ati_sb_cfg.sata_channel > 0){		// enable sata
			switch(sata_class){
				case 0 :
				case 3 :
				case 4 :
					temp = _pci_conf_read(sata_dev, 0x40);
					temp |= (ati_sb_cfg.sb600_sata_sts & 0xFF0F) << 16;
					_pci_conf_write(sata_dev, 0x40, temp);
				default :

			}
		}
	}

	return;
}
示例#24
0
void sb_last_post_setting(void)
{
	u8 rev = get_sb600_revision();
	pcitag_t pcib_dev;

	PRINTF_DEBUG();
	if(rev == REV_SB600_A11){
		update_hpet_table();
	}
	if(rev == REV_SB600_A12){
		/* clear HPET ECC */
		set_pm_enable_bits(0x9A, 1 << 7, 0 << 7);
	}
	if(rev >= REV_SB600_A13){
		/* clear HPET ECC */
		set_pm_enable_bits(0x9A, 1 << 7, 0 << 7);
		/* enable load new value for HPET */
		set_pm_enable_bits(0x9F, 1 << 5, 1 << 5);
		/* make HPET revision id to be 0x01 */
		set_pm_enable_bits(0x9E, (1 << 6) | (1 << 7), (1 << 6) | (1 << 7));
	}

	if(ati_sb_cfg.hpet_en == SB_DISABLE){
		update_hpet_table();
	}
	
	/* RPR4.5 Master Latency Timer PCIB_PCI_config 0x0D/0x1B = 0x40
	 * Enables the PCIB to retain ownership of the bus on the
	 * Primary side and on the Secondary side when GNT# is deasserted.
	 */
	pcib_dev = _pci_make_tag(0, 20, 4);
	_pci_conf_writen(pcib_dev, 0x0D, 0x40, 1);
	_pci_conf_writen(pcib_dev, 0x1B, 0x40, 1);

	return;
}
示例#25
0
/* php_spintf_appenddouble() {{{ */
inline static void
php_sprintf_appenddouble(char **buffer, int *pos,
						 int *size, double number,
						 int width, char padding,
						 int alignment, int precision,
						 int adjust, char fmt,
						 int always_sign
						 TSRMLS_DC)
{
	char num_buf[NUM_BUF_SIZE];
	char *s = NULL;
	int s_len = 0, is_negative = 0;
#ifdef HAVE_LOCALE_H
	struct lconv *lconv;
#endif

	PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n",
				  *buffer, pos, size, number, width, padding, alignment, fmt));
	if ((adjust & ADJ_PRECISION) == 0) {
		precision = FLOAT_PRECISION;
	} else if (precision > MAX_FLOAT_PRECISION) {
		php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Requested precision of %d digits was truncated to PHP maximum of %d digits", precision, MAX_FLOAT_PRECISION);
		precision = MAX_FLOAT_PRECISION;
	}
	
	if (zend_isnan(number)) {
		is_negative = (number<0);
		php_sprintf_appendstring(buffer, pos, size, "NaN", 3, 0, padding,
								 alignment, 3, is_negative, 0, always_sign);
		return;
	}

	if (zend_isinf(number)) {
		is_negative = (number<0);
		php_sprintf_appendstring(buffer, pos, size, "INF", 3, 0, padding,
								 alignment, 3, is_negative, 0, always_sign);
		return;
	}

	switch (fmt) {			
		case 'e':
		case 'E':
		case 'f':
		case 'F':
#ifdef HAVE_LOCALE_H
			lconv = localeconv();
#endif
			s = php_conv_fp((fmt == 'f')?'F':fmt, number, 0, precision,
						(fmt == 'f')?LCONV_DECIMAL_POINT:'.',
						&is_negative, &num_buf[1], &s_len);
			if (is_negative) {
				num_buf[0] = '-';
				s = num_buf;
				s_len++;
			} else if (always_sign) {
				num_buf[0] = '+';
				s = num_buf;
				s_len++;
			}
			break;

		case 'g':
		case 'G':
			if (precision == 0)
				precision = 1;
			/*
			 * * We use &num_buf[ 1 ], so that we have room for the sign
			 */
#ifdef HAVE_LOCALE_H
			lconv = localeconv();
#endif
			s = php_gcvt(number, precision, LCONV_DECIMAL_POINT, (fmt == 'G')?'E':'e', &num_buf[1]);
			is_negative = 0;
			if (*s == '-') {
				is_negative = 1;
				s = &num_buf[1];
			} else if (always_sign) {
				num_buf[0] = '+';
				s = num_buf;
			}

			s_len = strlen(s);
			break;
	}

	php_sprintf_appendstring(buffer, pos, size, s, width, 0, padding,
							 alignment, s_len, is_negative, 0, always_sign);
}
示例#26
0
/*
 * sata_drive_detect :
 * detect the sata drive and put it into proper config
 */
static void sata_drive_detecting(void)
{
	int ports = 4, count;
	int timeout;
	u32	base, reg32, reg04;
	u32 val;
    pcitag_t sata_dev = _pci_make_tag(0, 18, 0);
	
	PRINTF_DEBUG();
	reg04 = _pci_conf_read(sata_dev, 0x04);
	/* force memory and io enabled */
	set_sbcfg_enable_bits(sata_dev, 0x04, 0x03 << 0, 0x03 << 0);
	
	/* ahci base addr */
	base = (_pci_conf_read(sata_dev, 0x24) & 0xfffffff0) | 0xA0000000;
	DEBUG_INFO("ahci base addr is %x \n", base);
	
	/* 4/PM 3/SM 2/PS 1/SS */
	while(ports){
		count = 3;	
		while(count){
			/* judge is the phy and communication is ok */
			delay(1000);	// delay 1 ms
			reg32 = *(volatile u32 *)(base + 0x128);
			DEBUG_INFO("sata status : reg128 0x%x\n", reg32);
			if((reg32 & 0x0000000F) == 0x03){
				goto drive_is_stable;	
			}

			/* test if bsy bit is set, it means the drive is connected */
			reg32 = *(volatile u32 *)(base + 0x120);
			if((reg32 & 0x80) == 0){
				val = *(volatile u32 *)(base + 0x128);
				if((val & 0x0f) != 0x1){
					goto drive_is_stable;	
				}
			}
			count--;
		}

		/* now drive is not stable even after waitting for 1 sec,so downgrade to GEN 1 */	
		reg32 = *(volatile u32 *)(base + 0x12C);
		if((reg32 & 0x0f) == 0x10){
			goto drive_is_stable;	// jump if already GEN1
		}
				
		/* store the sata status */
		ati_sb_cfg.sb600_sata_sts |= (0x8 << ports);
		
		/* set to GEN1 : reset the status*/
		reg32 = *(volatile u32 *)(base + 0x12C);
		reg32 = (reg32 & 0x0f) | 0x10;
		*(volatile u32 *)(base + 0x12C) = reg32;
		reg32 |= 0x01;
		*(volatile u32 *)(base + 0x12C) = reg32; // force 00B
		delay(1000); //wait 1 ms
		reg32 = *(volatile u32 *)(base + 0x12C);
		reg32 &= 0xfe;
		*(volatile u32 *)(base + 0x12C) = reg32;
		/* re detect the device again */
		ports--;
				continue;

drive_is_stable:
		reg32 = *(volatile u32 *)(base + 0x128);
		if ((reg32 & 0x0f) == 0x3){
			u16  sata_bar;
			
			sata_bar = _pci_conf_readn(sata_dev, 0x10, 2);
			if(ports & 0x01){
				sata_bar = _pci_conf_readn(sata_dev, 0x18, 2);
			}
			sata_bar &= ~(7);
			sata_bar += 0x06;

			if(ports <= 2){
				val |= 0xA0;
			}else{
				val |= 0xB0;
			}
			linux_outb(val, sata_bar);

			sata_bar++;
			timeout = 3000;
			while(timeout--){
				val = linux_inb(sata_bar);
				val &= 0x88000000;
				if(val == 0x00){
					break;
				}
				delay(10 * 1000);
			}
			/* update the status */
			ati_sb_cfg.sb600_sata_sts ^= (1 << (4 - ports));
		}
		base += 0x80; // increase status offset by 80h for next port
		--ports;
	} /* while(i) */

	/* restore PCI conf cmd */
	_pci_conf_write(sata_dev, 0x04, reg04);
	return;
}
示例#27
0
文件: netdrv.c 项目: ariavie/bcm
/**
 *
 * NetdrvMemInit - initialize memory for the chip
 *
 * This routine is highly specific to the device.
 *
 * Input: device to be initialized
 * RETURNS: OK or ERROR.
 *
 *
 **/
STATUS
NetdrvMemInit(END_DEVICE * pDrvCtrl)
{
    

    /*
     * This is how we would set up and END netPool using netBufLib(1).
     * This code is pretty generic.
     */
    if(pDrvCtrl == NULL)
        return ERROR;

    if((pDrvCtrl->end.pNetPool = malloc (sizeof(NET_POOL))) == NULL)
        return (ERROR);

    NetdrvMclBlkConfig.mBlkNum = 1024 /*32*/;
    NetdrvClDescTbl[0].clNum = 512 /* 1MB */;
    NetdrvMclBlkConfig.clBlkNum = NetdrvClDescTbl[0].clNum;

    /* Calculate the total memory for all the M-Blks and CL-Blks. */
    NetdrvMclBlkConfig.memSize =
        (NetdrvMclBlkConfig.mBlkNum * (MSIZE + sizeof (int))) +
        (NetdrvMclBlkConfig.clBlkNum * (CL_BLK_SZ));

    NetdrvMclBlkConfig.memArea =
        (char *) memalign (4, (UINT) NetdrvMclBlkConfig.memSize);

    if(NetdrvMclBlkConfig.memArea == NULL)
        return (ERROR);

    /* Calculate the memory size of all the clusters. */
    NetdrvClDescTbl[0].memSize = (NetdrvClDescTbl[0].clNum *
        (NetdrvClDescTbl[0].clSize + sizeof(int)));

    /* Allocate the memory for the clusters from cache safe memory. */
    NetdrvClDescTbl[0].memArea =
        (char *) sal_dma_alloc(NetdrvClDescTbl[0].memSize, "mema");

    if (NetdrvClDescTbl[0].memArea == NULL) {
        PRINTF_ERROR(("\r\nsystem memory unavailable!"));
        return (ERROR);
    }

    /* Initialize the memory pool. */
    if (netPoolInit(pDrvCtrl->end.pNetPool, &NetdrvMclBlkConfig,
        &NetdrvClDescTbl[0], NetdrvClDescTblNumEnt, NULL) == ERROR) {
        PRINTF_ERROR(("\r\nCould not init buffering"));
        return (ERROR);
    }

    /*
     * If you need clusters to store received packets into then get them
     * here ahead of time.
     */
    if ((pDrvCtrl->pClPoolId =
        netClPoolIdGet (pDrvCtrl->end.pNetPool, sizeof (RFD), FALSE)) == NULL) {
        return (ERROR);
    }

    PRINTF_DEBUG(("\r\nMemory setup complete"));

    return OK;
}
示例#28
0
/* php_formatted_print() {{{
 * New sprintf implementation for PHP.
 *
 * Modifiers:
 *
 *  " "   pad integers with spaces
 *  "-"   left adjusted field
 *   n    field size
 *  "."n  precision (floats only)
 *  "+"   Always place a sign (+ or -) in front of a number
 *
 * Type specifiers:
 *
 *  "%"   literal "%", modifiers are ignored.
 *  "b"   integer argument is printed as binary
 *  "c"   integer argument is printed as a single character
 *  "d"   argument is an integer
 *  "f"   the argument is a float
 *  "o"   integer argument is printed as octal
 *  "s"   argument is a string
 *  "x"   integer argument is printed as lowercase hexadecimal
 *  "X"   integer argument is printed as uppercase hexadecimal
 *
 */
static char *
php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC)
{
	zval ***args, **z_format;
	int argc, size = 240, inpos = 0, outpos = 0, temppos;
	int alignment, currarg, adjusting, argnum, width, precision;
	char *format, *result, padding;
	int always_sign;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
		return NULL;
	}

	/* verify the number of args */
	if ((use_array && argc != (2 + format_offset)) 
			|| (!use_array && argc < (1 + format_offset))) {
		efree(args);
		WRONG_PARAM_COUNT_WITH_RETVAL(NULL);
	}
	
	if (use_array) {
		int i = 1;
		zval ***newargs;
		zval **array;

		z_format = args[format_offset];
		array = args[1 + format_offset];
		
		SEPARATE_ZVAL(array);
		convert_to_array_ex(array);
		
		argc = 1 + zend_hash_num_elements(Z_ARRVAL_PP(array));
		newargs = (zval ***)safe_emalloc(argc, sizeof(zval *), 0);
		newargs[0] = z_format;
		
		for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(array));
			 zend_hash_get_current_data(Z_ARRVAL_PP(array), (void **)&newargs[i++]) == SUCCESS;
			 zend_hash_move_forward(Z_ARRVAL_PP(array)));

		efree(args);
		args = newargs;
		format_offset = 0;
	}
	
	convert_to_string_ex(args[format_offset]);
	format = Z_STRVAL_PP(args[format_offset]);
	result = emalloc(size);

	currarg = 1;

	while (inpos<Z_STRLEN_PP(args[format_offset])) {
		int expprec = 0, multiuse = 0;
		zval *tmp;

		PRINTF_DEBUG(("sprintf: format[%d]='%c'\n", inpos, format[inpos]));
		PRINTF_DEBUG(("sprintf: outpos=%d\n", outpos));
		if (format[inpos] != '%') {
			php_sprintf_appendchar(&result, &outpos, &size, format[inpos++] TSRMLS_CC);
		} else if (format[inpos + 1] == '%') {
			php_sprintf_appendchar(&result, &outpos, &size, '%' TSRMLS_CC);
			inpos += 2;
		} else {
			/* starting a new format specifier, reset variables */
			alignment = ALIGN_RIGHT;
			adjusting = 0;
			padding = ' ';
			always_sign = 0;
			inpos++;			/* skip the '%' */

			PRINTF_DEBUG(("sprintf: first looking at '%c', inpos=%d\n",
						  format[inpos], inpos));
			if (isascii((int)format[inpos]) && !isalpha((int)format[inpos])) {
				/* first look for argnum */
				temppos = inpos;
				while (isdigit((int)format[temppos])) temppos++;
				if (format[temppos] == '$') {
					argnum = php_sprintf_getnumber(format, &inpos);

					if (argnum <= 0) {
						efree(result);
						efree(args);
						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument number must be greater than zero");
						return NULL;
					}

					multiuse = 1;
					inpos++;  /* skip the '$' */
				} else {
					argnum = currarg++;
				}

				argnum += format_offset;

				/* after argnum comes modifiers */
				PRINTF_DEBUG(("sprintf: looking for modifiers\n"
							  "sprintf: now looking at '%c', inpos=%d\n",
							  format[inpos], inpos));
				for (;; inpos++) {
					if (format[inpos] == ' ' || format[inpos] == '0') {
						padding = format[inpos];
					} else if (format[inpos] == '-') {
						alignment = ALIGN_LEFT;
						/* space padding, the default */
					} else if (format[inpos] == '+') {
						always_sign = 1;
					} else if (format[inpos] == '\'') {
						padding = format[++inpos];
					} else {
						PRINTF_DEBUG(("sprintf: end of modifiers\n"));
						break;
					}
				}
				PRINTF_DEBUG(("sprintf: padding='%c'\n", padding));
				PRINTF_DEBUG(("sprintf: alignment=%s\n",
							  (alignment == ALIGN_LEFT) ? "left" : "right"));


				/* after modifiers comes width */
				if (isdigit((int)format[inpos])) {
					PRINTF_DEBUG(("sprintf: getting width\n"));
					if ((width = php_sprintf_getnumber(format, &inpos)) < 0) {
						efree(result);
						efree(args);
						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Width must be greater than zero and less than %d", INT_MAX);
						return NULL;
					}
					adjusting |= ADJ_WIDTH;
				} else {
					width = 0;
				}
				PRINTF_DEBUG(("sprintf: width=%d\n", width));

				/* after width and argnum comes precision */
				if (format[inpos] == '.') {
					inpos++;
					PRINTF_DEBUG(("sprintf: getting precision\n"));
					if (isdigit((int)format[inpos])) {
						if ((precision = php_sprintf_getnumber(format, &inpos)) < 0) {
							efree(result);
							efree(args);
							php_error_docref(NULL TSRMLS_CC, E_WARNING, "Precision must be greater than zero and less than %d", INT_MAX);
							return NULL;
						}
						adjusting |= ADJ_PRECISION;
						expprec = 1;
					} else {
						precision = 0;
					}
				} else {
					precision = 0;
				}
				PRINTF_DEBUG(("sprintf: precision=%d\n", precision));
			} else {
				width = precision = 0;
				argnum = currarg++ + format_offset;
			}

			if (argnum >= argc) {
				efree(result);
				efree(args);
				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too few arguments");
				return NULL;
			}

			if (format[inpos] == 'l') {
				inpos++;
			}
			PRINTF_DEBUG(("sprintf: format character='%c'\n", format[inpos]));
			/* now we expect to find a type specifier */
			if (multiuse) {
				MAKE_STD_ZVAL(tmp);
				*tmp = **(args[argnum]);
				INIT_PZVAL(tmp);
				zval_copy_ctor(tmp);
			} else {
				SEPARATE_ZVAL(args[argnum]);
				tmp = *(args[argnum]);
			}

			switch (format[inpos]) {
				case 's': {
					zval *var, var_copy;
					int use_copy;

					zend_make_printable_zval(tmp, &var_copy, &use_copy);
					if (use_copy) {
						var = &var_copy;
					} else {
						var = tmp;
					}
					php_sprintf_appendstring(&result, &outpos, &size,
											 Z_STRVAL_P(var),
											 width, precision, padding,
											 alignment,
											 Z_STRLEN_P(var),
											 0, expprec, 0);
					if (use_copy) {
						zval_dtor(&var_copy);
					}
					break;
				}

				case 'd':
					convert_to_long(tmp);
					php_sprintf_appendint(&result, &outpos, &size,
										  Z_LVAL_P(tmp),
										  width, padding, alignment,
										  always_sign);
					break;

				case 'u':
					convert_to_long(tmp);
					php_sprintf_appenduint(&result, &outpos, &size,
										  Z_LVAL_P(tmp),
										  width, padding, alignment);
					break;

				case 'g':
				case 'G':
				case 'e':
				case 'E':
				case 'f':
				case 'F':
					convert_to_double(tmp);
					php_sprintf_appenddouble(&result, &outpos, &size,
											 Z_DVAL_P(tmp),
											 width, padding, alignment,
											 precision, adjusting,
											 format[inpos], always_sign
											 TSRMLS_CC);
					break;
					
				case 'c':
					convert_to_long(tmp);
					php_sprintf_appendchar(&result, &outpos, &size,
										(char) Z_LVAL_P(tmp) TSRMLS_CC);
					break;

				case 'o':
					convert_to_long(tmp);
					php_sprintf_append2n(&result, &outpos, &size,
										 Z_LVAL_P(tmp),
										 width, padding, alignment, 3,
										 hexchars, expprec);
					break;

				case 'x':
					convert_to_long(tmp);
					php_sprintf_append2n(&result, &outpos, &size,
										 Z_LVAL_P(tmp),
										 width, padding, alignment, 4,
										 hexchars, expprec);
					break;

				case 'X':
					convert_to_long(tmp);
					php_sprintf_append2n(&result, &outpos, &size,
										 Z_LVAL_P(tmp),
										 width, padding, alignment, 4,
										 HEXCHARS, expprec);
					break;

				case 'b':
					convert_to_long(tmp);
					php_sprintf_append2n(&result, &outpos, &size,
										 Z_LVAL_P(tmp),
										 width, padding, alignment, 1,
										 hexchars, expprec);
					break;

				case '%':
					php_sprintf_appendchar(&result, &outpos, &size, '%' TSRMLS_CC);

					break;
				default:
					break;
			}
			if (multiuse) {
				zval_ptr_dtor(&tmp);
			}
			inpos++;
		}
	}
	
	efree(args);
	
	/* possibly, we have to make sure we have room for the terminating null? */
	result[outpos]=0;
	*len = outpos;	
	return result;
}
int query_result_to_cstring(const char* path, char res_string[], size_t size, ngx_http_request_t *r)
{
    int ret = 0;
    res_string[0] = '\0';

    static MYSQL *kconn = NULL;
    static int kconnected = 0;
    static int kconnect_times = 0;
    static int kquery_times = 0;

    if(!kconnected) {
        kconnect_times ++;

        char server[] = "localhost";
        char user[] = "root";
        char password[] = "mysql@ubuntu";
        char database[] = "notetask";
    
        kconn = mysql_init(NULL);
    
        if (!mysql_real_connect(kconn, server,user, password, database, 0, NULL, 0)) {
            PRINTF_ERROR("mysql connect error : %s\n", mysql_error(kconn));
            mysql_close(kconn);
            mysql_library_end();
            kconn = NULL;
            kconnected = 0;
            ret = -1;
            goto finish;
        }
            else {
            PRINTF_DEBUG("mysql connect OK [%d].\n", getpid());
            kconnected = 1;
            }
    }

    //根据请求的path, 组合查询语句.
    #define LEN_QUERY_STRING (1024)
    char query_string[LEN_QUERY_STRING];
    snprintf(query_string, LEN_QUERY_STRING, "%s", "select * from notetask"); 

    int ret_query = mysql_query(kconn, query_string);
    kquery_times ++;
    if(ret_query) {
        PRINTF_ERROR("mysql query error : %s\n", mysql_error(kconn));
        mysql_close(kconn);
        mysql_library_end();
        kconn = NULL;
        kconnected = 0;
        ret = -1;
        goto finish;
    }

    MYSQL_ROW sqlrow;
    MYSQL_RES *res_ptr;

    size_t len = 0;

    res_ptr = mysql_store_result(kconn);

    int64_t uid = 100;
    int type = 1;
    int count = 18;
    int version = 667;
    int status = 0;

    const char* title = "当前任务";
    int page = 1;
    int code = 200;
    int success = 1;
    const char* message = "";
    len += snprintf(res_string, size-len, 
            "{"
                "\"notetasks\":{"
                    "\"uid\":%"PRIu64","
                    "\"type\":%d,"
                    "\"count\":%d,"
                    "\"version\":%d,"
                    "\"server\":\"%d.%d.%d.%d\","
                    "\"status\":%d"
                "},"
                "\"page\":{"
                    "\"title\":\"%s\","
                    "\"page\":%d"
                "},"
                "\"code\":%d,"
                "\"success\":%s,"
                "\"message\":\"%s\","
                "\"notes\":[", 
                    uid,
                    type,
                    count,
                    version,
                    ngx_getpid(), ngx_log_tid, kconnect_times, kquery_times,
                    status,
                    title, 
                    page,
                    code,
                    success?"true":"false",
                    message);

    int row_number = 0;

    if(res_ptr) {
        while((sqlrow = mysql_fetch_row(res_ptr)) && len + 1 < size) {

            row_number ++;

            len += snprintf(res_string + len, size - len, 
                    "%s{"
                        "\"uid\":%s," 
                        "\"status\":%s," 
                        "\"startDateTime\":\"%s\"," 
                        "\"finishDateTime\":\"%s\"," 
                        "\"commitDateTime\":\"%s\"," 
                        "\"updateDateTime\":\"%s\"," 
                        "\"content\":\"%s\","
                        "\"isShared\":%s,"
                        "\"isOnlyLocal\":%s,"
                        "\"isOnlyWorkday\":%s,"
                        "\"isDailyRepeat\":%s,"
                        "\"isWeeklyRepeat\":%s,"
                        "\"isYearlyRepeat\":%s,"
                        "\"commentNumber\":%ld,"
                        "\"likeNumber\":%ld"
                    "}", 
                    row_number > 1 ? "," : "", 
                    sqlrow[1],
                    sqlrow[2],
                    sqlrow[3],
                    sqlrow[4],
                    sqlrow[5],
                    sqlrow[6],
                    sqlrow[7],
                    sqlrow[8],
                    sqlrow[9],
                    sqlrow[10],
                    sqlrow[11],
                    sqlrow[12],
                    sqlrow[13],
                    atol(sqlrow[14]),
                    atol(sqlrow[15])
                        );
        }

        if(len+1 < size) {
            len += snprintf(res_string + len, size - len, 
                "]"
                "}");
        }

        mysql_free_result(res_ptr);
        res_ptr = NULL;
    }
    else {
        PRINTF_ERROR("mysql_use_result error : %s.\n", mysql_error(kconn));
        mysql_close(kconn);
        mysql_library_end();
        kconn = NULL;
        kconnected = 0;
        ret = -1;
        goto finish;
    }

finish:
    return ret;
}
static ngx_int_t
ngx_http_notetask_handler(ngx_http_request_t *r)
{ENTER
        ngx_int_t    rc;
        ngx_buf_t   *b;
        ngx_chain_t  out;
        ngx_http_notetask_loc_conf_t* my_conf;

#define LEN_RESPONSE_STRING (1024*1024)
        u_char ngx_notetask_string[LEN_RESPONSE_STRING] = {0};
        ngx_uint_t content_length = 0;

        ngx_log_error(NGX_LOG_EMERG, r->connection->log, 0, "n1gx_http_notetask_handler is called!");

        my_conf = ngx_http_get_module_loc_conf(r, ngx_http_notetask_module);
        if (my_conf->notetask_string.len == 0 )
        {
                ngx_log_error(NGX_LOG_EMERG, r->connection->log, 0, "notetask_string is empty!");
                return NGX_DECLINED;
        }

#if 0
        if (my_conf->notetask_counter == NGX_CONF_UNSET
                || my_conf->notetask_counter == 0)
        {
                ngx_sprintf(ngx_notetask_string, "%s", my_conf->notetask_string.data);
        }
        else
        {
                ngx_sprintf(ngx_notetask_string, "%s Visited Times:%d", my_conf->notetask_string.data,
                        ++ngx_notetask_visited_times);
        }
#endif

        setbuf(stdout, NULL);
        //char s[LEN_RESPONSE_STRING]; s[0] = '\0';
        int total_times = 1;//100*1024;
        struct timeval tvs;
        struct timeval tve;
        gettimeofday(&tvs, NULL);
        while(total_times --) {
            static int ktest_times = 0;
            query_result_to_cstring("/", (char*)ngx_notetask_string, LEN_RESPONSE_STRING, r);
            ktest_times ++;
            if(0 == ktest_times % 10240) {
                printf(".%zd %d\n", strlen((char*)ngx_notetask_string), ktest_times);
            }
        }
        gettimeofday(&tve, NULL);
        long usec = tve.tv_usec-tvs.tv_usec;
        if(usec >= 0) {
            PRINTF_DEBUG("%ld.%06ld", tve.tv_sec-tvs.tv_sec, usec);
        }
        else {
            PRINTF_DEBUG("%ld.%06ld", tve.tv_sec-tvs.tv_sec-1, usec+1000000);
        }

        PRINTF_DEBUG("notetask_string:%s", ngx_notetask_string);
        content_length = ngx_strlen(ngx_notetask_string);
        PRINTF_DEBUG("[%zd]\n", content_length);

        /* we response to 'GET' and 'HEAD' requests only */
        if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_POST))) {
                return NGX_HTTP_NOT_ALLOWED;
        }

        /* discard request body, since we don't need it here */
        rc = ngx_http_discard_request_body(r);

        if (rc != NGX_OK) {
                return rc;
        }

        /* set the 'Content-type' header */
        /*
         *r->headers_out.content_type.len = sizeof("text/html") - 1;
         *r->headers_out.content_type.data = (u_char *)"text/html";
         */
        ngx_str_set(&r->headers_out.content_type, "text/html");


        /* send the header only, if the request type is http 'HEAD' */
        if (r->method == NGX_HTTP_HEAD) {
                r->headers_out.status = NGX_HTTP_OK;
                r->headers_out.content_length_n = content_length;

                return ngx_http_send_header(r);
        }

        /* allocate a buffer for your response body */
        b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
        if (b == NULL) {
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
        }

        /* attach this buffer to the buffer chain */
        out.buf = b;
        out.next = NULL;

        /* adjust the pointers of the buffer */
        b->pos = ngx_notetask_string;
        b->last = ngx_notetask_string + content_length;
        b->memory = 1;    /* this buffer is in memory */
        b->last_buf = 1;  /* this is the last buffer in the buffer chain */

        /* set the status line */
        r->headers_out.status = NGX_HTTP_OK;
        r->headers_out.content_length_n = content_length;

        /* send the headers of your response */
        rc = ngx_http_send_header(r);

        if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
                return rc;
        }

        /* send the buffer chain of your response */
        return ngx_http_output_filter(r, &out);
}