Skip to contentSkip to conversation

TCG on PowerPC arch

Qemu-devel Salvatore Lionetti 5 participants 12 messages Oct 22, 2008 – Nov 3, 2008

lore
Share & tools
lore
#0 lore raw

Hi,

There need help about TCG porting on PowerPC?
I'm moderating skilled on PowerPC ASM, expecially on PPC405GPr For this last uP, i've build a board so could also test result.

In the case, i need info about TCG
Have a good day

Scopri il blog di Yahoo! Mail:
Trucchi, novità e scrivi la tua opinione.
http://www.ymailblogit.com/blog

#1 lore raw
Quoted 6 lines · Salvatore Lionetti

Hi,

There need help about TCG porting on PowerPC?
I'm moderating skilled on PowerPC ASM, expecially on PPC405GPr For this last uP, i've build a board so could also test result.

I am currently doing the conversion, with a few other sending patches. You can also send patches to help. Testing is also welcome. I do check before commiting the changes, but I may miss a few bugs.

Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net
#2 lore raw
In reply to Salvatore Lionetti

Hi,

Am 22.10.2008 um 10:18 schrieb Salvatore Lionetti:

Quoted 3 lines

There need help about TCG porting on PowerPC?
I'm moderating skilled on PowerPC ASM, expecially on PPC405GPr For this last uP, i've build a board so could also test result.

What about your previous ppc patch? Have you had time to rework it yet, so that it can be applied?

Regards,
Andreas

#3 lore raw

Sure!

since i never created patch, also to reduce integration effort, i split patch in three activity (starting from 0.9.1):

- Activity [emac device] {hw/emac.c, hw/ppc405_uc.c} now ethernet, using vlan driver, work!
Now ppc405GPr could be used as 405EP
To test use ./qemu ... -net nic -net tap,ifname=qemu_network ...
- Activity [cfi flash] {hw/pflash_cfi02.c cpu-all.h} Intro 'buffer load mode'
- Activity [major fix] {vl.c hw/ppc.c}
reset: unprogram PIT on chip, core, system reset
focus: initial focus in monitor when load very great sized elf

I try to attach to svn view.

PATCH TO INTRODUCE EMAC (hw\emac.c, hw\ppc405_uc.c)

hw/emac.c renamed from ../qemu-0.9.1-orig/hw/emac.c +591 -0
@@ -0,0 +1,591 @@
+/*
+ * QEMU EMAC emulation
+ *
+ * Copyright (c) 2008, Lionetti Salvatore [email protected]
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "hw.h"
+#include "ppc.h"
+#include "ppc405.h"
+#include "pc.h"
+#include "qemu-timer.h"
+#include "sysemu.h"
+#include "net.h"
+
+/* #define DEBUG_EMAC */
+#ifdef DEBUG_EMAC
+#define DPRINT(fmt, args...)                           \
+    do { printf("%s: " fmt , __func__, ##args); } while (0)
+#else
+#define DPRINT(fmt, args...)
+#endif 
+
+/* 
+ * Redefined because if !exist, linker gives a warning but produce qemu,
+ * but on execution this call cause problem
+ * (could be cygwin & mingw cohesistence?)
+ */
+#if (defined(WORDS_BIGENDIAN) && defined(TARGET_WORDS_BIGENDIAN)) || ((!defined(WORDS_BIGENDIAN) && !defined(TARGET_WORDS_BIGENDIAN)))
+#if 0
+static unsigned long int htonl(unsigned long int hostlong);
+static unsigned short int htons(unsigned short int hostshort);
+#endif
+static unsigned long int ntohl(unsigned long int ing) {
+	return ing;
+}
+static unsigned short int ntohs(unsigned short int ing) {
+	return ing;
+}
+#else
+static unsigned long int ntohl(unsigned long int ing) {
+	unsigned char tmp;
+	unsigned char* tmpp = (unsigned char*)&ing;
+	tmp=tmpp[0]; tmpp[0]=tmpp[3]; tmpp[3]=tmp;
+	tmp=tmpp[1]; tmpp[1]=tmpp[2]; tmpp[2]=tmp;
+	return *(unsigned long int*)tmpp;
+}
+static unsigned short int ntohs(unsigned short int ing) {
+	return ((ing&0xFF)<<8) | ((ing&0xFF00)>>8);
+}
+#endif
+
+/* qemu initialization:
+ *
+ * parse command line:	call net_client_init() for each -net, either for {if, collision domain} options.
+ * 			==========					================
+ * 			IF MAC=...	<==== Vlan{Id,Ptr} ====>	COLLISION DOMAIN (mean N-1 other IF MAC=...)
+ * 			========== 					================
+ * 				-net nic[,...]:	fill field onto nd_table[] {MAC(cl|auto), model, vlanPtr=f(vlanId)}
+ * 						vlanPtr=f(vlanId)->guest++
+ * 				-net tap[,...]: vlanPtr=f(vlanId)->host ++
+ * 						tap_win32_init(vlanPtr, "ifname=tap..."):
+ * 							qemu_new_vlan_client(vlanPtr,tap_receive, tap* opaque)		RECV
+ * 							qemu_add_wait_object(tap_sem, tap_w32_send, tap* opaque)	SEND
+ * 			
+ * 			For each vlan created,
+ * 				exit if no GUEST & some HOST
+ * 				warn if some GUEST & no HOST
+ * 											  
+ * start machine:	Es ppc (also pc use n2000) call machine->init():
+ * 			isa_ne2000_init(base, irqno, &nd_table[i])
+ * 				register_ioport_write(base + ..., ne2000_asic_ioport_write, opaque NE2000State*);	SEND
+ * 				qemu_new_vlan_client(nd->vlan, ne2000_receive, ne2000_can_receive, opaque NE2000State*) RECV
+ *
+ * Done!!!
+ *
+ * qemu runtime scenario:
+ *
+ * packet send from HOST:	a signal (after exec() cycle) is sent to tap_sem => tap_w32_send() => tap_win32_read()
+ * 				if some bytes returned => qemu_send_packet() => send to all 'client' (better peer) of
+ * 				such vlan, different from itself => ne2000_receive()
+ *
+ * packet send from GUEST:	in machine code we call qemu_send_packet() => (prec) => tap_receive() => tap_w32_write()
+ *
+ *
+ * So onto VLAN actors always call qemu_send_packet() that dispatch packet to all peer attached to same vlan.
+ *
+ */
+/* PPC405 layer 2, reversed MII mode:
+ *
+ * Register@0xEF600000 already mapped.
+ * Configuration RW:
+ *
+ * Read(ind, data):
+ * 	[EMAC0_STACR] <= (STACR_STAC_R | ind)
+ *	[EMAC0_STACR] & STACR_OC must goes to 0
+ *	[EMAC0_STACR] => >>16 => data
+ *
+ * Write(ind, data)
+ * 	[EMAC0_STACR] <= (STACR_STAC_W | ind | data<<16)
+ * 	[EMAC0_STACR] & STACR_OC must goes to 0
+ *
+ * Physical access:
+ * Read(ind_phy, ind_reg, data)
+ * 	[EMAC0_STACR] <= (STACR_STAC_W | TANTOS_REG_MIIAC | (ind_reg&0x1F | OP_READ | (ind_phy&0x1F)<<5))>>16
+ * 	[EMAC0_STACR] & STACR_OC must goes to 0
+ *	
+ *	Verify:
+ *	[EMAC0_STACR] <= (STACR_STAC_R | TANTOS_REG_MIIRD)
+ * 	[EMAC0_STACR] & STACR_OC must goes to 0
+ * 	[EMAC0_STACR] => data
+ * 	data & STACR_PHYE should be 0
+ * 	data=data>>16
+ *
+ * Tantos Stub Layer: (needed?)
+ */
+// For PPC405
+#define EMAC0_BASE        0xEF600800
+#define EMAC0_STACR_DISP  0x35
+#define EMAC0_STACR      (EMAC0_BASE + EMAC0_STACR_DISP) /* 4 byte addressing */
+#define STACR_OC          0x00008000 /* Occupied flag */
+#define STACR_PHYE        0x00004000
+#define STACR_STAC_W      0x00002000
+#define STACR_STAC_R      0x00001000
+
+#define TANTOS_REG_MIIAC    0x120      /// TANTOS3G MII indirect acess registers
+#define TANTOS_REG_MIIWD    0x121
+#define TANTOS_REG_MIIRD    0x122
+#define OP_WRITE	0x0400
+#define OP_READ		0x0800
+#define MBUSY 		0x8000
+
+/* WORDS_BIGENDIAN = FALSE su HOST i386, GUEST ppc
+ * per cui e' l'architetura HOST
+ */
+struct EmacMalRxDes {
+#ifdef WORDS_BIGENDIAN
+#error "Host endianism BUG: To Test!!!"
+#else
+    union {
+	    struct { /* Mal */
+		    unsigned int emac1_nu	: 2;
+		    unsigned int bit5_intr	: 1;
+		    unsigned int bit4_first	: 1;
+		    unsigned int bit3_last	: 1;
+		    unsigned int bit2_contm	: 1;
+		    unsigned int bit1_wrap	: 1;
+		    unsigned int bit0_empty	: 1;
+		    unsigned int emac2_nu	: 8; 
+	    } __attribute__ ((packed)) mal;
+	    struct { /* Status: Read access, error cause */
+		    unsigned int bit7_pausepacket	: 1;
+		    unsigned int bit6_overrun		: 1;
+		    unsigned int mal_nu			: 6;
+		    unsigned int bit15_inrange		: 1;
+		    unsigned int bit14_outrange		: 1;
+		    unsigned int bit13_longpacket	: 1;
+		    unsigned int bit12_fcs		: 1;
+		    unsigned int bit11_alignment	: 1;
+		    unsigned int bit10_shortevent	: 1;
+		    unsigned int bit9_runtpacket	: 1;
+		    unsigned int bit8_badpacket		: 1;
+	    } __attribute__ ((packed)) emac_errstatus;
+    } __attribute__ ((packed));
+#endif
+    unsigned short len;
+    unsigned char* buf;
+} __attribute__ ((packed)); /* Host endianism, to be converted */
+struct EmacMalTxDes {
+#ifdef WORDS_BIGENDIAN
+#error "Host endianism BUG: To Test!!!"
+#else
+    union {
+	    struct { /* Mal */
+		    unsigned int emac1_nu	: 2;
+		    unsigned int bit5_intr	: 1;
+		    unsigned int bit4_resv	: 1;
+		    unsigned int bit3_last	: 1;
+		    unsigned int bit2_contm	: 1;
+		    unsigned int bit1_wrap	: 1;
+		    unsigned int bit0_ready	: 1;
+		    unsigned int emac2_nu	: 8; 
+	    } __attribute__ ((packed)) mal;
+	    struct { /* Status: Read access, error cause */
+		    unsigned int bit7_badpacket		: 1;
+		    unsigned int bit6_badfsc		: 1;
+		    unsigned int mal_nu			: 6;
+		    unsigned int bit15_sqe		: 1;
+		    unsigned int bit14_underrun		: 1;
+		    unsigned int bit13_singlecoll	: 1;
+		    unsigned int bit12_multiplecoll	: 1;
+		    unsigned int bit11_latecoll		: 1;
+		    unsigned int bit10_excessivecoll	: 1;
+		    unsigned int bit9_excessivedeferral : 1;
+		    unsigned int bit8_lossofcarrier	: 1;
+	    } __attribute__ ((packed)) emac_errorstatus;
+	    struct { /* Control: Write access */
+		    unsigned int bit7_generatepad	: 1;
+		    unsigned int bit6_generatefcs	: 1;
+		    unsigned int mal_nu			: 6;
+		    unsigned int emac_nu		: 4;
+		    unsigned int bit11_vlantag_replace	: 1;
+		    unsigned int bit10_vlantag_insert	: 1;
+		    unsigned int bit9_sourceaddr_insert	: 1;
+		    unsigned int bit8_sourceaddr_replace: 1;
+	    } __attribute__ ((packed)) emac_control;
+    };
+#endif
+    unsigned short len;
+    unsigned char* buf;
+}__attribute__ ((packed)); /* Host endianism, to be converted */
+
+
+typedef struct ppc4xx_emac_t ppc4xx_emac_t;
+struct ppc4xx_emac_t {
+    /* Guest related */
+    target_phys_addr_t base;
+    NICInfo nic;
+    /* To remove, already defined in mal */
+    qemu_irq mal_irqs_txeob;
+    qemu_irq mal_irqs_rxeob;
+    qemu_irq mal_irqs_txerr;
+    qemu_irq mal_irqs_rxerr;
+    qemu_irq mal_irqs_syserr;
+
+    struct EmacMalTxDes* tx;
+    struct EmacMalRxDes* rx;
+
+    int txPos, rxPos;
+    int txNum, rxNum;
+
+    int rxStarted, txStarted;
+    int rxLostNum, rxLostLimit;
+
+    /* Host related */
+    VLANClientState *vc;
+    QEMUTimer* tx_timer;
+};
+
+#if 0
+#define EMACMAL_EMPTY 0x8000
+#define EMACMAL_WRAP  0x8000
+#define EMACMAL_EMPTY 0x8000
+#define EMACMAL_EMPTY 0x8000
+void EmacMalDes_readFromTarget(struct EmacMalDes* host, struct EmacMalDes* guest) {
+
+    host->status = ntohs(guest->status);
+    host->len = ntohs(guest->len);
+    host->buf = htol(guest->buf);
+}
+void EmacMalDes_writeToTarget(struct EmacMalDes* host, struct EmacMalDes* guest) {
+}
+#endif
+void EmacMalRxDes_dump(struct EmacMalRxDes* des) {
+	printf("des@0x%p |%2.2X|%2X|%02X|%02X| len %d buf 0x%p\n",des,((char*)des)[0], ((char*)des)[1], ((char*)des)[2], ((char*)des)[3], ntohs(des->len), (unsigned char*)ntohl((unsigned long int)des->buf));
+	printf("mal: empty%d wrap%d contm %d last%d first%d intr%d\n",
+			des->mal.bit0_empty, des->mal.bit1_wrap, des->mal.bit2_contm, des->mal.bit3_last, des->mal.bit4_first, des->mal.bit5_intr);
+}
+void EmacMalTxDes_dump(struct EmacMalTxDes* des) {
+	printf("des@0x%p |%2.2X|%2.2X|%02X|%02X| len %d buf 0x%p\n",des,((char*)des)[0], ((char*)des)[1], ((char*)des)[2], ((char*)des)[3], des->len, des->buf);
+	printf("mal: ready%d wrap%d contm %d last%d first%d intr%d\n",
+			des->mal.bit0_ready, des->mal.bit1_wrap, des->mal.bit2_contm, des->mal.bit3_last, des->mal.bit4_resv, des->mal.bit5_intr);
+}
+static int emac_buffer_full(ppc4xx_emac_t *s)
+{
+#if 0
+    int avail, index, boundary;
+
+    index = s->curpag << 8;
+    boundary = s->boundary << 8;
+    if (index < boundary)
+        avail = boundary - index;
+    else
+        avail = (s->stop - s->start) - (index - boundary);
+    if (avail < (MAX_ETH_FRAME_SIZE + 4))
+        return 1;
+#endif
+    return 0;
+}
+
+static int emac_can_receive(void *opaque)
+{
+#if 0
+    NE2000State *s = opaque;
+
+    if (s->cmd & E8390_STOP)
+        return 1;
+    return !ne2000_buffer_full(s);
+#endif
+    return 0;
+}
+
+#define MIN_BUF_SIZE 60
+
+static void emac_receive(void *opaque, const uint8_t *buf, int size)
+{
+    ppc4xx_emac_t* emac = (ppc4xx_emac_t*) opaque;
+
+#ifdef DEBUG_EMAC
+    EmacMalRxDes_dump(emac->rx);
+#endif
+    DPRINT("%d bytes\n", size);
+    if (emac->rxStarted) {
+    if (emac->rx->buf) {
+    if (size<1520) {
+	    if (emac->rx[emac->rxPos].mal.bit0_empty) {
+	    /* data is allocated with the maximum possible length, on eth = 1520Bytes
+	     * len field represent packet size.*/
+		    /* We !use Continuos mode, first & last field ignored */
+		    unsigned char* dstG = (unsigned char*) ntohl((unsigned long int)emac->rx[emac->rxPos].buf);
+		    unsigned char* dstH= dstG+(unsigned int)phys_ram_base;
+		    unsigned short size16 = size;
+/*		    DPRINT(" Delivery message HOST 0x%p-> GUEST 0x%p,pos%d", dstH, dstG, emac->rxPos);*/
+		    memcpy(dstH, buf, size);	
+		    emac->rx[emac->rxPos].len = ntohs(size16);
+		    emac->rx[emac->rxPos].mal.bit0_empty = 0;
+		    if (emac->rx[emac->rxPos].mal.bit5_intr)
+			    qemu_irq_raise(emac->mal_irqs_rxeob);
+
+		    emac->rxPos += (emac->rx[emac->rxPos].mal.bit1_wrap)? -(emac->rxPos) : 1;
+	    } else {
+		    if (++emac->rxLostNum == emac->rxLostLimit) {
+			    printf(" %d Message lost, board seem hung up!\n", emac->rxLostNum);
+			    emac->rxLostLimit*=10;
+		    }
+	    }
+    } else {
+	    printf(" Message load, too long for 1 rx des\n");
+    }
+    } else {
+	    printf(" Driver !ready (buf==0)\n");
+    }
+    } else {
+	    /*printf(" Driver !command rx start yet!!!\n");*/
+    }
+#if 0
+    NE2000State *s = opaque;
+    uint8_t *p;
+    unsigned int total_len, next, avail, len, index, mcast_idx;
+    uint8_t buf1[60];
+    static const uint8_t broadcast_macaddr[6] =
+        { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+#if defined(DEBUG_NE2000)
+    printf("NE2000: received len=%d\n", size);
+#endif
+
+    if (s->cmd & E8390_STOP || ne2000_bufstruct mal_emac_bdfer_full(s))
+        return;
+
+    /* XXX: check this */
+    if (s->rxcr & 0x10) {
+        /* promiscuous: receive all */
+    } else {
+        if (!memcmp(buf,  broadcast_macaddr, 6)) {
+            /* broadcast address */
+            if (!(s->rxcr & 0x04))
+                return;
+        } else if (buf[0] & 0x01) {
+            /* multicast */
+            if (!(s->rxcr & 0x08))
+                return;
+            mcast_idx = compute_mcast_idx(buf);
+            if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))
+                return;
+        } else if (s->mem[0] == buf[0] &&
+                   s->mem[2] == buf[1] &&
+                   s->mem[4] == buf[2] &&
+                   s->mem[6] == buf[3] &&
+                   s->mem[8] == buf[4] &&
+                   s->mem[10] == buf[5]) {
+            /* match */
+        } else {
+            return;
+        }
+    }
+
+
+    /* if too small buffer, then expand it */
+    if (size < MIN_BUF_SIZE) {
+        memcpy(buf1, buf, size);
+        memset(buf1 + size, 0, MIN_BUF_SIZE - size);
+        buf = buf1;
+        size = MIN_BUF_SIZE;
+    }
+
+    index = s->curpag << 8;
+    /* 4 bytes for header */
+    total_len = size + 4;
+    /* address for next packet (4 bytes for CRC) */
+    next = index + ((total_len + 4 + 255) & ~0xff);
+    if (next >= s->stop)
+        next -= (s->stop - s->start);
+    /* prepare packet header */
+    p = s->mem + index;
+    s->rsr = ENRSR_RXOK; /* receive status */
+    /* XXX: check this */
+    if (buf[0] & 0x01)
+        s->rsr |= ENRSR_PHY;
+    p[0] = s->rsr;
+    p[1] = next >> 8;
+    p[2] = total_len;
+    p[3] = total_len >> 8;
+    index += 4;
+
+    /* write packet data */
+    while (size > 0) {
+        if (index <= s->stop)
+            avail = s->stop - index;
+        else
+            avail = 0;
+        len = size;
+        if (len > avail)
+            len = avail;
+        memcpy(s->mem + index, buf, len);
+        buf += len;
+        index += len;
+        if (index == s->stop)
+            index = s->start;
+        size -= len;
+    }
+    s->curpag = next >> 8;
+
+    /* now we can signal we have received something */
+    s->isr |= ENISR_RX;
+    ne2000_update_irq(s);
+#endif
+}
+
+void emac_ppc405_init(ppc4xx_emac_t* emac, NICInfo *nd)
+{
+    memcpy(&emac->nic, nd, sizeof(NICInfo));
+    /* We are only be able to receive. Sending packet mean receiver action get up */
+    emac->vc = qemu_new_vlan_client(nd->vlan, emac_receive,
+                                 NULL/*emac_can_receive*/, emac);
+
+    snprintf(emac->vc->info_str, sizeof(emac->vc->info_str),
+             "emac macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             emac->nic.macaddr[0],
+             emac->nic.macaddr[1],
+             emac->nic.macaddr[2],
+             emac->nic.macaddr[3],
+             emac->nic.macaddr[4],
+             emac->nic.macaddr[5]);
+}
+
+static void ppc4xx_emac_reset (void *opaque)
+{
+    ppc4xx_emac_t *emac;
+
+    emac = opaque;
+    emac->rx = (struct EmacMalRxDes*) (phys_ram_base + 0x0000C000);
+    emac->tx = (struct EmacMalTxDes*) (phys_ram_base + 0x0000C000 + 16*8);
+    emac->txPos = emac->rxPos = 0;
+    emac->txNum = emac->rxNum = 0;
+    emac->rxStarted = emac->txStarted = 0;
+    emac->rxLostNum=0;
+    emac->rxLostLimit=1;
+}
+/* It looks like a lot of Linux programs assume page size
+ * is 4kB long. This is evil, but we have to deal with it...
+ *
+#define TARGET_PAGE_BITS 12
+ */
+static uint32_t emac_readl (void *opaque, target_phys_addr_t addr)
+{
+	return STACR_OC;
+}
+
+static void emac_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
+{
+	ppc4xx_emac_t* emac = (ppc4xx_emac_t*)opaque;
+
+/*	printf("%s: " PADDRX " val %x\n",__func__, addr, value);*/
+	if (addr-emac->base==0) {
+		/* soft reset */
+		if (value & 0x20000000) {
+			printf("emac: soft reset commanded!\n");
+			ppc4xx_emac_reset(emac); /* Should be protected with a semaphore, also in emac_receive()? */
+		}
+		/* rx enable */
+		if (value & 0x08000000) {
+			emac->rxStarted=1;
+			printf("emac: rx started!\n");
+		}
+		/* tx enable */
+		if (value & 0x10000000) {
+			emac->txStarted=1;
+			printf("emac: tx started!\n");
+			/* A timer that periodically check packet to send 
+			emac->tx_timer = qemu_new_timer();*/
+		}
+	}
+	if (addr-emac->base==8) {
+		if (value & 0x80000000) {
+			if (emac->txStarted==1) {
+			if (emac->tx[emac->txPos].mal.bit0_ready) {
+				unsigned char* dstG = (unsigned char*) ntohl((unsigned long int)emac->tx[emac->txPos].buf);
+				unsigned char* dstH= dstG+(unsigned int)phys_ram_base;
+				unsigned short size16 = ntohs(emac->tx[emac->txPos].len);
+
+				DPRINT("Sending packet on pos %d\n", emac->txPos);
+				qemu_send_packet(emac->vc, dstH, size16);
+				if (emac->tx[emac->txPos].mal.bit5_intr)
+					qemu_irq_raise(emac->mal_irqs_txeob);
+
+				/* Clear status */
+				emac->tx[emac->txPos].mal.bit0_ready = 0;
+				/* 0x808 is stucked at STACR_OC */
+				emac->txPos += (emac->tx[emac->txPos].mal.bit1_wrap)? -(emac->txPos) : 1;
+			} else {printf("Processor goes crazy(ready bit was 0)!!! Stopping tx\n");emac->txStarted=2;}
+			} else {if (emac->txStarted!=2) printf("Tx is disabled\n");}
+		}
+	}
+}
+static uint32_t emac_readw (void *opaque, target_phys_addr_t addr)
+{
+	printf("Lettura a granularita' word su EMAC " PADDRX "\n",addr);
+	return 0;
+}
+
+static void emac_writew (void *opaque, target_phys_addr_t addr, uint32_t value)
+{
+	printf("Scrittura a granularita' word su EMAC " PADDRX "\n",addr);
+}
+
+static uint32_t emac_readb (void *opaque, target_phys_addr_t addr)
+{
+	printf("Lettura a granularita' byte su EMAC " PADDRX "\n",addr);
+	return 0;
+}
+
+static void emac_writeb (void *opaque, target_phys_addr_t addr, uint32_t value)
+{
+	printf("Scrittura a granularita' byte su EMAC " PADDRX "\n",addr);
+}
+
+
+static CPUReadMemoryFunc *emac_read[] = {
+    &emac_readb,
+    &emac_readw,
+    &emac_readl,
+};
+
+static CPUWriteMemoryFunc *emac_write[] = {
+    &emac_writeb,
+    &emac_writew,
+    &emac_writel,
+};
+void ppc4xx_emac_init (CPUState *env, ppc4xx_mmio_t *mmio, target_phys_addr_t offset, NICInfo *nic, qemu_irq mal_irqs[4])
+{
+    ppc4xx_emac_t *emac;
+
+    emac = qemu_mallocz(sizeof(ppc4xx_emac_t));
+    if (emac != NULL) {
+        emac->base = offset;
+#ifdef DEBUG_OPBA
+        printf("%s: offset " PADDRX "\n", __func__, offset);
+#endif
+        ppc4xx_mmio_register(env, mmio, offset, 0x70,
+                             emac_read, emac_write, emac);
+        qemu_register_reset(ppc4xx_emac_reset, emac);
+
+	/* One time configuration, HOST related */
+	emac_ppc405_init(emac, nic);
+
+	emac->mal_irqs_txeob = mal_irqs[3];
+	emac->mal_irqs_rxeob = mal_irqs[2];
+	emac->mal_irqs_txerr = mal_irqs[1];
+	emac->mal_irqs_rxerr = mal_irqs[0];
+
+	/* N Time configuration, GUEST related */
+        ppc4xx_emac_reset(emac);
+    }
+}
hw/ppc405_uc.c renamed from ../qemu-0.9.1-orig/hw/ppc405_uc.c +45 -20

140 lines not on this page · raw message

===================================================================
=== PATCH TO ENHACE FLASH DEVICE (hw\pflash_cfi02.c, cpu-all.h) ===
===================================================================

cpu-all.h +2 -0
@@ -773,6 +773,8 @@ target_phys_addr_t cpu_get_phys_page_deb
 #define CPU_LOG_PCALL      (1 << 6)
 #define CPU_LOG_IOPORT     (1 << 7)
 #define CPU_LOG_TB_CPU     (1 << 8)
+#define FLASH_LOG_CFI      (1 << 9)
+#define FPGA_LOG_ACCESS    (1 << 10)
 
 /* define log items */
 typedef struct CPULogItem {
hw/pflash_cfi02.c +281 -99

667 lines not on this page · raw message

This is a list of all file modified, just to describe all modification done.

Modified file in private view:
cpu-all.h
- Add flag

exec.c
- Change in log filename
- help message for new flag

exec-all.h
- Add logfilename as extern

vl.c
- change /tmp/... in (char*)logfilename

hw/pflash_cfi02.c
- Add 'buffer load mode'
- Some optimization in write

hw/ppc.c
- On uP reset, cancel any pending WDT, PIT, FIT

hw/ppc405_uc.c
- Change in bcr from FFE28000 -> FE0A2000
- Change ocm from qemu code
- I2C controller now have hook to call board specific behaviour
- 405GPr approximated as 405EP + CR0
- ppc405cr_init() now return a list of created device, so in qemu code one can interact with they (es ocm, bcr)
- in ppc405ep_init() start EMAC layer, to have networking

hw\emac.c
- Simulate EMAC, a 'FastEthController' for ppc405GPr uP, only on LittleEndian host.

target-ppc\translate.c
- Enable some bad access to !existing spr, unassigned memroy region (no machine {data|instruction} exception start yet)

Have a good day

--- Sab 25/10/08, Andreas Färber <[email protected]> ha scritto:

Quoted 13 lines

Da: Andreas Färber <[email protected]>
Oggetto: Re: [Qemu-devel] TCG on PowerPC arch
A: "Salvatore Lionetti" <[email protected]>
Cc: [email protected]
Data: Sabato 25 ottobre 2008, 22:51
Hi,

Am 22.10.2008 um 10:18 schrieb Salvatore Lionetti:

Quoted 2 lines

There need help about TCG porting on PowerPC?
I'm moderating skilled on PowerPC ASM, expecially

on PPC405GPr

Quoted 1 line

For this last uP, i've build a board so could also

Quoted 8 lines

test result.

What about your previous ppc patch? Have you had time to rework it
yet, so that it can be applied?

Regards,
Andreas

Scopri il blog di Yahoo! Mail:
Trucchi, novità e scrivi la tua opinione.
http://www.ymailblogit.com/blog

#4 lore raw
In reply to Andreas Färber

Sure!

since i never created patch, also to reduce integration effort, i split patch in three activity (starting from 0.9.1):

- Activity [emac device] {hw/emac.c, hw/ppc405_uc.c} now ethernet, using vlan driver, work!
Now ppc405GPr could be used as 405EP
To test use ./qemu ... -net nic -net tap,ifname=qemu_network ...
- Activity [cfi flash] {hw/pflash_cfi02.c cpu-all.h} Intro 'buffer load mode'
- Activity [major fix] {vl.c hw/ppc.c}
reset: unprogram PIT on chip, core, system reset
focus: initial focus in monitor when load very great sized elf

I try to attach to svn view.

PATCH TO INTRODUCE EMAC (hw\emac.c, hw\ppc405_uc.c)

hw/emac.c renamed from ../qemu-0.9.1-orig/hw/emac.c +591 -0
@@ -0,0 +1,591 @@
+/*
+ * QEMU EMAC emulation
+ *
+ * Copyright (c) 2008, Lionetti Salvatore [email protected]
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "hw.h"
+#include "ppc.h"
+#include "ppc405.h"
+#include "pc.h"
+#include "qemu-timer.h"
+#include "sysemu.h"
+#include "net.h"
+
+/* #define DEBUG_EMAC */
+#ifdef DEBUG_EMAC
+#define DPRINT(fmt, args...)                           \
+    do { printf("%s: " fmt , __func__, ##args); } while (0)
+#else
+#define DPRINT(fmt, args...)
+#endif 
+
+/* 
+ * Redefined because if !exist, linker gives a warning but produce qemu,
+ * but on execution this call cause problem
+ * (could be cygwin & mingw cohesistence?)
+ */
+#if (defined(WORDS_BIGENDIAN) && defined(TARGET_WORDS_BIGENDIAN)) || ((!defined(WORDS_BIGENDIAN) && !defined(TARGET_WORDS_BIGENDIAN)))
+#if 0
+static unsigned long int htonl(unsigned long int hostlong);
+static unsigned short int htons(unsigned short int hostshort);
+#endif
+static unsigned long int ntohl(unsigned long int ing) {
+	return ing;
+}
+static unsigned short int ntohs(unsigned short int ing) {
+	return ing;
+}
+#else
+static unsigned long int ntohl(unsigned long int ing) {
+	unsigned char tmp;
+	unsigned char* tmpp = (unsigned char*)&ing;
+	tmp=tmpp[0]; tmpp[0]=tmpp[3]; tmpp[3]=tmp;
+	tmp=tmpp[1]; tmpp[1]=tmpp[2]; tmpp[2]=tmp;
+	return *(unsigned long int*)tmpp;
+}
+static unsigned short int ntohs(unsigned short int ing) {
+	return ((ing&0xFF)<<8) | ((ing&0xFF00)>>8);
+}
+#endif
+
+/* qemu initialization:
+ *
+ * parse command line:	call net_client_init() for each -net, either for {if, collision domain} options.
+ * 			==========					================
+ * 			IF MAC=...	<==== Vlan{Id,Ptr} ====>	COLLISION DOMAIN (mean N-1 other IF MAC=...)
+ * 			========== 					================
+ * 				-net nic[,...]:	fill field onto nd_table[] {MAC(cl|auto), model, vlanPtr=f(vlanId)}
+ * 						vlanPtr=f(vlanId)->guest++
+ * 				-net tap[,...]: vlanPtr=f(vlanId)->host ++
+ * 						tap_win32_init(vlanPtr, "ifname=tap..."):
+ * 							qemu_new_vlan_client(vlanPtr,tap_receive, tap* opaque)		RECV
+ * 							qemu_add_wait_object(tap_sem, tap_w32_send, tap* opaque)	SEND
+ * 			
+ * 			For each vlan created,
+ * 				exit if no GUEST & some HOST
+ * 				warn if some GUEST & no HOST
+ * 											  
+ * start machine:	Es ppc (also pc use n2000) call machine->init():
+ * 			isa_ne2000_init(base, irqno, &nd_table[i])
+ * 				register_ioport_write(base + ..., ne2000_asic_ioport_write, opaque NE2000State*);	SEND
+ * 				qemu_new_vlan_client(nd->vlan, ne2000_receive, ne2000_can_receive, opaque NE2000State*) RECV
+ *
+ * Done!!!
+ *
+ * qemu runtime scenario:
+ *
+ * packet send from HOST:	a signal (after exec() cycle) is sent to tap_sem => tap_w32_send() => tap_win32_read()
+ * 				if some bytes returned => qemu_send_packet() => send to all 'client' (better peer) of
+ * 				such vlan, different from itself => ne2000_receive()
+ *
+ * packet send from GUEST:	in machine code we call qemu_send_packet() => (prec) => tap_receive() => tap_w32_write()
+ *
+ *
+ * So onto VLAN actors always call qemu_send_packet() that dispatch packet to all peer attached to same vlan.
+ *
+ */
+/* PPC405 layer 2, reversed MII mode:
+ *
+ * Register@0xEF600000 already mapped.
+ * Configuration RW:
+ *
+ * Read(ind, data):
+ * 	[EMAC0_STACR] <= (STACR_STAC_R | ind)
+ *	[EMAC0_STACR] & STACR_OC must goes to 0
+ *	[EMAC0_STACR] => >>16 => data
+ *
+ * Write(ind, data)
+ * 	[EMAC0_STACR] <= (STACR_STAC_W | ind | data<<16)
+ * 	[EMAC0_STACR] & STACR_OC must goes to 0
+ *
+ * Physical access:
+ * Read(ind_phy, ind_reg, data)
+ * 	[EMAC0_STACR] <= (STACR_STAC_W | TANTOS_REG_MIIAC | (ind_reg&0x1F | OP_READ | (ind_phy&0x1F)<<5))>>16
+ * 	[EMAC0_STACR] & STACR_OC must goes to 0
+ *	
+ *	Verify:
+ *	[EMAC0_STACR] <= (STACR_STAC_R | TANTOS_REG_MIIRD)
+ * 	[EMAC0_STACR] & STACR_OC must goes to 0
+ * 	[EMAC0_STACR] => data
+ * 	data & STACR_PHYE should be 0
+ * 	data=data>>16
+ *
+ * Tantos Stub Layer: (needed?)
+ */
+// For PPC405
+#define EMAC0_BASE        0xEF600800
+#define EMAC0_STACR_DISP  0x35
+#define EMAC0_STACR      (EMAC0_BASE + EMAC0_STACR_DISP) /* 4 byte addressing */
+#define STACR_OC          0x00008000 /* Occupied flag */
+#define STACR_PHYE        0x00004000
+#define STACR_STAC_W      0x00002000
+#define STACR_STAC_R      0x00001000
+
+#define TANTOS_REG_MIIAC    0x120      /// TANTOS3G MII indirect acess registers
+#define TANTOS_REG_MIIWD    0x121
+#define TANTOS_REG_MIIRD    0x122
+#define OP_WRITE	0x0400
+#define OP_READ		0x0800
+#define MBUSY 		0x8000
+
+/* WORDS_BIGENDIAN = FALSE su HOST i386, GUEST ppc
+ * per cui e' l'architetura HOST
+ */
+struct EmacMalRxDes {
+#ifdef WORDS_BIGENDIAN
+#error "Host endianism BUG: To Test!!!"
+#else
+    union {
+	    struct { /* Mal */
+		    unsigned int emac1_nu	: 2;
+		    unsigned int bit5_intr	: 1;
+		    unsigned int bit4_first	: 1;
+		    unsigned int bit3_last	: 1;
+		    unsigned int bit2_contm	: 1;
+		    unsigned int bit1_wrap	: 1;
+		    unsigned int bit0_empty	: 1;
+		    unsigned int emac2_nu	: 8; 
+	    } __attribute__ ((packed)) mal;
+	    struct { /* Status: Read access, error cause */
+		    unsigned int bit7_pausepacket	: 1;
+		    unsigned int bit6_overrun		: 1;
+		    unsigned int mal_nu			: 6;
+		    unsigned int bit15_inrange		: 1;
+		    unsigned int bit14_outrange		: 1;
+		    unsigned int bit13_longpacket	: 1;
+		    unsigned int bit12_fcs		: 1;
+		    unsigned int bit11_alignment	: 1;
+		    unsigned int bit10_shortevent	: 1;
+		    unsigned int bit9_runtpacket	: 1;
+		    unsigned int bit8_badpacket		: 1;
+	    } __attribute__ ((packed)) emac_errstatus;
+    } __attribute__ ((packed));
+#endif
+    unsigned short len;
+    unsigned char* buf;
+} __attribute__ ((packed)); /* Host endianism, to be converted */
+struct EmacMalTxDes {
+#ifdef WORDS_BIGENDIAN
+#error "Host endianism BUG: To Test!!!"
+#else
+    union {
+	    struct { /* Mal */
+		    unsigned int emac1_nu	: 2;
+		    unsigned int bit5_intr	: 1;
+		    unsigned int bit4_resv	: 1;
+		    unsigned int bit3_last	: 1;
+		    unsigned int bit2_contm	: 1;
+		    unsigned int bit1_wrap	: 1;
+		    unsigned int bit0_ready	: 1;
+		    unsigned int emac2_nu	: 8; 
+	    } __attribute__ ((packed)) mal;
+	    struct { /* Status: Read access, error cause */
+		    unsigned int bit7_badpacket		: 1;
+		    unsigned int bit6_badfsc		: 1;
+		    unsigned int mal_nu			: 6;
+		    unsigned int bit15_sqe		: 1;
+		    unsigned int bit14_underrun		: 1;
+		    unsigned int bit13_singlecoll	: 1;
+		    unsigned int bit12_multiplecoll	: 1;
+		    unsigned int bit11_latecoll		: 1;
+		    unsigned int bit10_excessivecoll	: 1;
+		    unsigned int bit9_excessivedeferral : 1;
+		    unsigned int bit8_lossofcarrier	: 1;
+	    } __attribute__ ((packed)) emac_errorstatus;
+	    struct { /* Control: Write access */
+		    unsigned int bit7_generatepad	: 1;
+		    unsigned int bit6_generatefcs	: 1;
+		    unsigned int mal_nu			: 6;
+		    unsigned int emac_nu		: 4;
+		    unsigned int bit11_vlantag_replace	: 1;
+		    unsigned int bit10_vlantag_insert	: 1;
+		    unsigned int bit9_sourceaddr_insert	: 1;
+		    unsigned int bit8_sourceaddr_replace: 1;
+	    } __attribute__ ((packed)) emac_control;
+    };
+#endif
+    unsigned short len;
+    unsigned char* buf;
+}__attribute__ ((packed)); /* Host endianism, to be converted */
+
+
+typedef struct ppc4xx_emac_t ppc4xx_emac_t;
+struct ppc4xx_emac_t {
+    /* Guest related */
+    target_phys_addr_t base;
+    NICInfo nic;
+    /* To remove, already defined in mal */
+    qemu_irq mal_irqs_txeob;
+    qemu_irq mal_irqs_rxeob;
+    qemu_irq mal_irqs_txerr;
+    qemu_irq mal_irqs_rxerr;
+    qemu_irq mal_irqs_syserr;
+
+    struct EmacMalTxDes* tx;
+    struct EmacMalRxDes* rx;
+
+    int txPos, rxPos;
+    int txNum, rxNum;
+
+    int rxStarted, txStarted;
+    int rxLostNum, rxLostLimit;
+
+    /* Host related */
+    VLANClientState *vc;
+    QEMUTimer* tx_timer;
+};
+
+#if 0
+#define EMACMAL_EMPTY 0x8000
+#define EMACMAL_WRAP  0x8000
+#define EMACMAL_EMPTY 0x8000
+#define EMACMAL_EMPTY 0x8000
+void EmacMalDes_readFromTarget(struct EmacMalDes* host, struct EmacMalDes* guest) {
+
+    host->status = ntohs(guest->status);
+    host->len = ntohs(guest->len);
+    host->buf = htol(guest->buf);
+}
+void EmacMalDes_writeToTarget(struct EmacMalDes* host, struct EmacMalDes* guest) {
+}
+#endif
+void EmacMalRxDes_dump(struct EmacMalRxDes* des) {
+	printf("des@0x%p |%2.2X|%2X|%02X|%02X| len %d buf 0x%p\n",des,((char*)des)[0], ((char*)des)[1], ((char*)des)[2], ((char*)des)[3], ntohs(des->len), (unsigned char*)ntohl((unsigned long int)des->buf));
+	printf("mal: empty%d wrap%d contm %d last%d first%d intr%d\n",
+			des->mal.bit0_empty, des->mal.bit1_wrap, des->mal.bit2_contm, des->mal.bit3_last, des->mal.bit4_first, des->mal.bit5_intr);
+}
+void EmacMalTxDes_dump(struct EmacMalTxDes* des) {
+	printf("des@0x%p |%2.2X|%2.2X|%02X|%02X| len %d buf 0x%p\n",des,((char*)des)[0], ((char*)des)[1], ((char*)des)[2], ((char*)des)[3], des->len, des->buf);
+	printf("mal: ready%d wrap%d contm %d last%d first%d intr%d\n",
+			des->mal.bit0_ready, des->mal.bit1_wrap, des->mal.bit2_contm, des->mal.bit3_last, des->mal.bit4_resv, des->mal.bit5_intr);
+}
+static int emac_buffer_full(ppc4xx_emac_t *s)
+{
+#if 0
+    int avail, index, boundary;
+
+    index = s->curpag << 8;
+    boundary = s->boundary << 8;
+    if (index < boundary)
+        avail = boundary - index;
+    else
+        avail = (s->stop - s->start) - (index - boundary);
+    if (avail < (MAX_ETH_FRAME_SIZE + 4))
+        return 1;
+#endif
+    return 0;
+}
+
+static int emac_can_receive(void *opaque)
+{
+#if 0
+    NE2000State *s = opaque;
+
+    if (s->cmd & E8390_STOP)
+        return 1;
+    return !ne2000_buffer_full(s);
+#endif
+    return 0;
+}
+
+#define MIN_BUF_SIZE 60
+
+static void emac_receive(void *opaque, const uint8_t *buf, int size)
+{
+    ppc4xx_emac_t* emac = (ppc4xx_emac_t*) opaque;
+
+#ifdef DEBUG_EMAC
+    EmacMalRxDes_dump(emac->rx);
+#endif
+    DPRINT("%d bytes\n", size);
+    if (emac->rxStarted) {
+    if (emac->rx->buf) {
+    if (size<1520) {
+	    if (emac->rx[emac->rxPos].mal.bit0_empty) {
+	    /* data is allocated with the maximum possible length, on eth = 1520Bytes
+	     * len field represent packet size.*/
+		    /* We !use Continuos mode, first & last field ignored */
+		    unsigned char* dstG = (unsigned char*) ntohl((unsigned long int)emac->rx[emac->rxPos].buf);
+		    unsigned char* dstH= dstG+(unsigned int)phys_ram_base;
+		    unsigned short size16 = size;
+/*		    DPRINT(" Delivery message HOST 0x%p-> GUEST 0x%p,pos%d", dstH, dstG, emac->rxPos);*/
+		    memcpy(dstH, buf, size);	
+		    emac->rx[emac->rxPos].len = ntohs(size16);
+		    emac->rx[emac->rxPos].mal.bit0_empty = 0;
+		    if (emac->rx[emac->rxPos].mal.bit5_intr)
+			    qemu_irq_raise(emac->mal_irqs_rxeob);
+
+		    emac->rxPos += (emac->rx[emac->rxPos].mal.bit1_wrap)? -(emac->rxPos) : 1;
+	    } else {
+		    if (++emac->rxLostNum == emac->rxLostLimit) {
+			    printf(" %d Message lost, board seem hung up!\n", emac->rxLostNum);
+			    emac->rxLostLimit*=10;
+		    }
+	    }
+    } else {
+	    printf(" Message load, too long for 1 rx des\n");
+    }
+    } else {
+	    printf(" Driver !ready (buf==0)\n");
+    }
+    } else {
+	    /*printf(" Driver !command rx start yet!!!\n");*/
+    }
+#if 0
+    NE2000State *s = opaque;
+    uint8_t *p;
+    unsigned int total_len, next, avail, len, index, mcast_idx;
+    uint8_t buf1[60];
+    static const uint8_t broadcast_macaddr[6] =
+        { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+#if defined(DEBUG_NE2000)
+    printf("NE2000: received len=%d\n", size);
+#endif
+
+    if (s->cmd & E8390_STOP || ne2000_bufstruct mal_emac_bdfer_full(s))
+        return;
+
+    /* XXX: check this */
+    if (s->rxcr & 0x10) {
+        /* promiscuous: receive all */
+    } else {
+        if (!memcmp(buf,  broadcast_macaddr, 6)) {
+            /* broadcast address */
+            if (!(s->rxcr & 0x04))
+                return;
+        } else if (buf[0] & 0x01) {
+            /* multicast */
+            if (!(s->rxcr & 0x08))
+                return;
+            mcast_idx = compute_mcast_idx(buf);
+            if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))
+                return;
+        } else if (s->mem[0] == buf[0] &&
+                   s->mem[2] == buf[1] &&
+                   s->mem[4] == buf[2] &&
+                   s->mem[6] == buf[3] &&
+                   s->mem[8] == buf[4] &&
+                   s->mem[10] == buf[5]) {
+            /* match */
+        } else {
+            return;
+        }
+    }
+
+
+    /* if too small buffer, then expand it */
+    if (size < MIN_BUF_SIZE) {
+        memcpy(buf1, buf, size);
+        memset(buf1 + size, 0, MIN_BUF_SIZE - size);
+        buf = buf1;
+        size = MIN_BUF_SIZE;
+    }
+
+    index = s->curpag << 8;
+    /* 4 bytes for header */
+    total_len = size + 4;
+    /* address for next packet (4 bytes for CRC) */
+    next = index + ((total_len + 4 + 255) & ~0xff);
+    if (next >= s->stop)
+        next -= (s->stop - s->start);
+    /* prepare packet header */
+    p = s->mem + index;
+    s->rsr = ENRSR_RXOK; /* receive status */
+    /* XXX: check this */
+    if (buf[0] & 0x01)
+        s->rsr |= ENRSR_PHY;
+    p[0] = s->rsr;
+    p[1] = next >> 8;
+    p[2] = total_len;
+    p[3] = total_len >> 8;
+    index += 4;
+
+    /* write packet data */
+    while (size > 0) {
+        if (index <= s->stop)
+            avail = s->stop - index;
+        else
+            avail = 0;
+        len = size;
+        if (len > avail)
+            len = avail;
+        memcpy(s->mem + index, buf, len);
+        buf += len;
+        index += len;
+        if (index == s->stop)
+            index = s->start;
+        size -= len;
+    }
+    s->curpag = next >> 8;
+
+    /* now we can signal we have received something */
+    s->isr |= ENISR_RX;
+    ne2000_update_irq(s);
+#endif
+}
+
+void emac_ppc405_init(ppc4xx_emac_t* emac, NICInfo *nd)
+{
+    memcpy(&emac->nic, nd, sizeof(NICInfo));
+    /* We are only be able to receive. Sending packet mean receiver action get up */
+    emac->vc = qemu_new_vlan_client(nd->vlan, emac_receive,
+                                 NULL/*emac_can_receive*/, emac);
+
+    snprintf(emac->vc->info_str, sizeof(emac->vc->info_str),
+             "emac macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             emac->nic.macaddr[0],
+             emac->nic.macaddr[1],
+             emac->nic.macaddr[2],
+             emac->nic.macaddr[3],
+             emac->nic.macaddr[4],
+             emac->nic.macaddr[5]);
+}
+
+static void ppc4xx_emac_reset (void *opaque)
+{
+    ppc4xx_emac_t *emac;
+
+    emac = opaque;
+    emac->rx = (struct EmacMalRxDes*) (phys_ram_base + 0x0000C000);
+    emac->tx = (struct EmacMalTxDes*) (phys_ram_base + 0x0000C000 + 16*8);
+    emac->txPos = emac->rxPos = 0;
+    emac->txNum = emac->rxNum = 0;
+    emac->rxStarted = emac->txStarted = 0;
+    emac->rxLostNum=0;
+    emac->rxLostLimit=1;
+}
+/* It looks like a lot of Linux programs assume page size
+ * is 4kB long. This is evil, but we have to deal with it...
+ *
+#define TARGET_PAGE_BITS 12
+ */
+static uint32_t emac_readl (void *opaque, target_phys_addr_t addr)
+{
+	return STACR_OC;
+}
+
+static void emac_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
+{
+	ppc4xx_emac_t* emac = (ppc4xx_emac_t*)opaque;
+
+/*	printf("%s: " PADDRX " val %x\n",__func__, addr, value);*/
+	if (addr-emac->base==0) {
+		/* soft reset */
+		if (value & 0x20000000) {
+			printf("emac: soft reset commanded!\n");
+			ppc4xx_emac_reset(emac); /* Should be protected with a semaphore, also in emac_receive()? */
+		}
+		/* rx enable */
+		if (value & 0x08000000) {
+			emac->rxStarted=1;
+			printf("emac: rx started!\n");
+		}
+		/* tx enable */
+		if (value & 0x10000000) {
+			emac->txStarted=1;
+			printf("emac: tx started!\n");
+			/* A timer that periodically check packet to send 
+			emac->tx_timer = qemu_new_timer();*/
+		}
+	}
+	if (addr-emac->base==8) {
+		if (value & 0x80000000) {
+			if (emac->txStarted==1) {
+			if (emac->tx[emac->txPos].mal.bit0_ready) {
+				unsigned char* dstG = (unsigned char*) ntohl((unsigned long int)emac->tx[emac->txPos].buf);
+				unsigned char* dstH= dstG+(unsigned int)phys_ram_base;
+				unsigned short size16 = ntohs(emac->tx[emac->txPos].len);
+
+				DPRINT("Sending packet on pos %d\n", emac->txPos);
+				qemu_send_packet(emac->vc, dstH, size16);
+				if (emac->tx[emac->txPos].mal.bit5_intr)
+					qemu_irq_raise(emac->mal_irqs_txeob);
+
+				/* Clear status */
+				emac->tx[emac->txPos].mal.bit0_ready = 0;
+				/* 0x808 is stucked at STACR_OC */
+				emac->txPos += (emac->tx[emac->txPos].mal.bit1_wrap)? -(emac->txPos) : 1;
+			} else {printf("Processor goes crazy(ready bit was 0)!!! Stopping tx\n");emac->txStarted=2;}
+			} else {if (emac->txStarted!=2) printf("Tx is disabled\n");}
+		}
+	}
+}
+static uint32_t emac_readw (void *opaque, target_phys_addr_t addr)
+{
+	printf("Lettura a granularita' word su EMAC " PADDRX "\n",addr);
+	return 0;
+}
+
+static void emac_writew (void *opaque, target_phys_addr_t addr, uint32_t value)
+{
+	printf("Scrittura a granularita' word su EMAC " PADDRX "\n",addr);
+}
+
+static uint32_t emac_readb (void *opaque, target_phys_addr_t addr)
+{
+	printf("Lettura a granularita' byte su EMAC " PADDRX "\n",addr);
+	return 0;
+}
+
+static void emac_writeb (void *opaque, target_phys_addr_t addr, uint32_t value)
+{
+	printf("Scrittura a granularita' byte su EMAC " PADDRX "\n",addr);
+}
+
+
+static CPUReadMemoryFunc *emac_read[] = {
+    &emac_readb,
+    &emac_readw,
+    &emac_readl,
+};
+
+static CPUWriteMemoryFunc *emac_write[] = {
+    &emac_writeb,
+    &emac_writew,
+    &emac_writel,
+};
+void ppc4xx_emac_init (CPUState *env, ppc4xx_mmio_t *mmio, target_phys_addr_t offset, NICInfo *nic, qemu_irq mal_irqs[4])
+{
+    ppc4xx_emac_t *emac;
+
+    emac = qemu_mallocz(sizeof(ppc4xx_emac_t));
+    if (emac != NULL) {
+        emac->base = offset;
+#ifdef DEBUG_OPBA
+        printf("%s: offset " PADDRX "\n", __func__, offset);
+#endif
+        ppc4xx_mmio_register(env, mmio, offset, 0x70,
+                             emac_read, emac_write, emac);
+        qemu_register_reset(ppc4xx_emac_reset, emac);
+
+	/* One time configuration, HOST related */
+	emac_ppc405_init(emac, nic);
+
+	emac->mal_irqs_txeob = mal_irqs[3];
+	emac->mal_irqs_rxeob = mal_irqs[2];
+	emac->mal_irqs_txerr = mal_irqs[1];
+	emac->mal_irqs_rxerr = mal_irqs[0];
+
+	/* N Time configuration, GUEST related */
+        ppc4xx_emac_reset(emac);
+    }
+}
hw/ppc405_uc.c renamed from ../qemu-0.9.1-orig/hw/ppc405_uc.c +45 -20

140 lines not on this page · raw message

===================================================================
=== PATCH TO ENHACE FLASH DEVICE (hw\pflash_cfi02.c, cpu-all.h) ===
===================================================================

cpu-all.h +2 -0
@@ -773,6 +773,8 @@ target_phys_addr_t cpu_get_phys_page_deb
 #define CPU_LOG_PCALL      (1 << 6)
 #define CPU_LOG_IOPORT     (1 << 7)
 #define CPU_LOG_TB_CPU     (1 << 8)
+#define FLASH_LOG_CFI      (1 << 9)
+#define FPGA_LOG_ACCESS    (1 << 10)
 
 /* define log items */
 typedef struct CPULogItem {
hw/pflash_cfi02.c +281 -99

667 lines not on this page · raw message

This is a list of all file modified, just to describe all modification done.

Modified file in private view:
cpu-all.h
- Add flag

exec.c
- Change in log filename
- help message for new flag

exec-all.h
- Add logfilename as extern

vl.c
- change /tmp/... in (char*)logfilename

hw/pflash_cfi02.c
- Add 'buffer load mode'
- Some optimization in write

hw/ppc.c
- On uP reset, cancel any pending WDT, PIT, FIT

hw/ppc405_uc.c
- Change in bcr from FFE28000 -> FE0A2000
- Change ocm from qemu code
- I2C controller now have hook to call board specific behaviour
- 405GPr approximated as 405EP + CR0
- ppc405cr_init() now return a list of created device, so in qemu code one can interact with they (es ocm, bcr)
- in ppc405ep_init() start EMAC layer, to have networking

hw\emac.c
- Simulate EMAC, a 'FastEthController' for ppc405GPr uP, only on LittleEndian host.

target-ppc\translate.c
- Enable some bad access to !existing spr, unassigned memroy region (no machine {data|instruction} exception start yet)

Have a good day

--- Sab 25/10/08, Andreas Färber <[email protected]> ha scritto:

Quoted 13 lines

Da: Andreas Färber <[email protected]>
Oggetto: Re: [Qemu-devel] TCG on PowerPC arch
A: "Salvatore Lionetti" <[email protected]>
Cc: [email protected]
Data: Sabato 25 ottobre 2008, 22:51
Hi,

Am 22.10.2008 um 10:18 schrieb Salvatore Lionetti:

Quoted 2 lines

There need help about TCG porting on PowerPC?
I'm moderating skilled on PowerPC ASM, expecially

on PPC405GPr

Quoted 1 line

For this last uP, i've build a board so could also

Quoted 8 lines

test result.

What about your previous ppc patch? Have you had time to rework it
yet, so that it can be applied?

Regards,
Andreas

Scopri il blog di Yahoo! Mail:
Trucchi, novità e scrivi la tua opinione.
http://www.ymailblogit.com/blog

#5 lore raw
Quoted 2 lines

+           struct { /* Mal */
+                   unsigned int emac1_nu       : 2;

Relying on a particular bitfield layout is a really bad idea. Don't do it.

Paul

#6 lore raw
In reply to Salvatore Lionetti

Hi,

Am 27.10.2008 um 16:29 schrieb Salvatore Lionetti:

Quoted 5 lines

- Activity [major fix] {vl.c hw/ppc.c}
reset: unprogram PIT on chip, core, system reset
focus: initial focus in monitor when load very great sized elf

I try to attach to svn view.

Not sure I understand correctly, but this last item seems to be missing here.
It would be good if you could check whether your patches still apply against the latest SVN version, if that's what you meant with the latter. ppc hardware probably hasn't changed so much since 0.9.1 but pflash might have.

hw/emac.c line 536

Quoted 5 lines
hw/emac.c renamed from ../qemu-0.9.1-orig/hw/emac.c +5 -0
+static uint32_t emac_readw (void *opaque, target_phys_addr_t addr)
+{
+	printf("Lettura a granularita' word su EMAC " PADDRX "\n",addr);
+	return 0;
+}

Some Italian slipped in here, also in some comments. Is the printf maybe a debug leftover that could be removed?

The split-up of your original patch looks okay, but for future submissions it would make review easier if you'd send only one of them at a time (e.g., mail subjects [PATCH 1/3], [PATCH 2/3] etc., see other examples).

How did you actually use and test your eMac emulation? I assume you did not use a PReP Linux kernel for that? If you could provide some details, that might help with testing the TCG conversion too.

Andreas

#7 lore raw

Ok,

thanks for your review!
Perhaps there was a lot of point to change and in the case, do it!
One of this is adding emac module in 'Makefile.target' (i forgot it!), but i think you just patch the patch !# For the italian comment, if it is necessary behead it, or better: globalize it ;)

Serious speaking we have to see at EBC and emulates hw by composing or filter readed byte from device. Should be useful an on demand warning per device(in my board fw access@width different from the preset in EBC Bank-i configuration register bits 17:18 is considered a bug) All this action should be done for the ppc4xx world.
In the mainwhile, for me, you can do anything you want about this read/write callback. On demand i'll adapt the code.

For me the main pb, due to my unknowing, is that i'm behind a proxy on Winzozz and svn give me timeout. Is the follow command correct? ->svn co svn://svn.sv.gnu.org/qemu/trunk

Next time i prefer also test latest svn before submit a patch, in the same way we do@work, avoiding unecessary work to this group.

I'm here for any pb related to this module
Thank you for attention
Salvatore

P.S: For the board, it is a commercial product so don't know if can give detail. Moreover i don't thing you need the exact board so, if agree, i create a new board from the previous.

P.P.S: In this board there is a way to configure qemu by file. I'd like to extent such concept, with correct namespace, configuration option.

--- Mar 28/10/08, Andreas Färber <[email protected]> ha scritto:

Quoted 47 lines

Da: Andreas Färber <[email protected]>
Oggetto: Re: [Qemu-devel] TCG on PowerPC arch
A: [email protected]
Cc: [email protected]
Data: Martedì 28 ottobre 2008, 21:41
Hi,

Am 27.10.2008 um 16:29 schrieb Salvatore Lionetti:

Quoted 3 lines

- Activity [major fix] {vl.c hw/ppc.c}
reset: unprogram PIT on chip, core, system reset
focus: initial focus in monitor when load very great

sized elf

Quoted 2 lines

I try to attach to svn view.

Not sure I understand correctly, but this last item seems to be
missing here.
It would be good if you could check whether your patches still apply
against the latest SVN version, if that's what you meant with the
latter.
ppc hardware probably hasn't changed so much since 0.9.1 but pflash
might have.

Quoted 1 line

+static uint32_t emac_readw (void *opaque,

target_phys_addr_t addr)

Review

Quoted 2 lines
(quoted diff) +2 -0
+{
+	printf("Lettura a granularita' word su EMAC

" PADDRX "\n",addr);

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

Some Italian slipped in here, also in some comments. Is the printf maybe a debug leftover that could be removed?

The split-up of your original patch looks okay, but for future
submissions it would make review easier if you'd send only one of them
at a time (e.g., mail subjects [PATCH 1/3], [PATCH 2/3] etc., see
other examples).

Quoted 8 lines

How did you actually use and test your eMac emulation? I assume you
did not use a PReP Linux kernel for that? If you could provide some
details, that might help with testing the TCG conversion too.

Andreas

Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo

#8 lore raw
In reply to Andreas Färber
Quoted 4 lines · Andreas Färber

How did you actually use and test your eMac emulation? I assume you did not use a PReP Linux kernel for that? If you could provide some details, that might help with testing the TCG conversion too.

(Just in case there's any confusion, EMAC is the name for the ethernet controller on IBM's 405- and 440-based SoCs, not to be confused with Apple's eMac product.)

Salvatore, did you use a 405 Linux kernel with the EMAC driver to test this patch? If so, how exactly did you boot? What did you do for firmware?

-Hollis

#9 lore raw

Hi Hollis,

please excuse me, but i can't release my firmware (based on OSE) If you agree, i'd like to
- catch svn status to test emac for my 405 based board, custom fw
- compile a linux kernel for ppc405 cpu, with emac driver (i've trying eCos but no emac driver :(0)

For first step actually have some pb with proxy script.
The second one is not strictly depend on me, but 'm very glad if anybody do it. Moreover emac driver in our custom firmware only used reversed mii, and is not well written code! so however i'd like to use another os. Moreover the emac device is tested only with such driver so i expect some pb during porting, so excuse in advance if some pb could arise.

Have a good day
Salvatore

--- Mer 29/10/08, Hollis Blanchard <[email protected]> ha scritto:

Quoted 20 lines

Da: Hollis Blanchard <[email protected]>
Oggetto: Re: [Qemu-devel] TCG on PowerPC arch
A: [email protected]
Cc: [email protected]
Data: Mercoledì 29 ottobre 2008, 16:15

Quoted 2 lines · Andreas Färber

How did you actually use and test your eMac emulation?

I assume you did not

Quoted 1 line

use a PReP Linux kernel for that? If you could provide

some details, that

Quoted 1 line

might help with testing the TCG conversion too.

(Just in case there's any confusion, EMAC is the name for the ethernet
controller on IBM's 405- and 440-based SoCs, not to be confused with
Apple's eMac product.)

Quoted 7 lines

Salvatore, did you use a 405 Linux kernel with the EMAC driver to test
this patch? If so, how exactly did you boot? What did you do for
firmware?

-Hollis

Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo

#10 lore raw

To summarize, you're saying that the only way you're able to test the EMAC patch is with a custom firmware you can't make public? Obviously that's not ideal, but I think some EMAC emulation is better than none at all, so IMHO that shouldn't necessarily block your patch.

The problem I had when trying to test qemu's 405 emulation was that Linux needed firmware to load it, and no 405 firmware is distributed with qemu. At the time, Jocelyn claimed we could download a binary
uboot image from AMCC, but that didn't actually work. (I think we
ended up using http://www.amcc.com/Embedded/Downloads/download.html?item=129&start=y).
This was probably a year ago, so details are fuzzy now.

However, if you have access to a 440 board, you could use KVM
(http://kvm.qumranet.com/kvmwiki/PowerPc) to boot a guest kernel with the EMAC driver and test that way. Qemu's instruction emulation doesn't support 440, but KVM implements all the instruction emulation itself and does run on 440.

Anyways, I definitely think it's worthwhile to update your patch to current SVN.

-Hollis

Quoted 49 lines · Salvatore Lionetti

Hi Hollis,

please excuse me, but i can't release my firmware (based on OSE) If you agree, i'd like to
- catch svn status to test emac for my 405 based board, custom fw
- compile a linux kernel for ppc405 cpu, with emac driver (i've trying eCos but no emac driver :(0)

For first step actually have some pb with proxy script.
The second one is not strictly depend on me, but 'm very glad if anybody do it. Moreover emac driver in our custom firmware only used reversed mii, and is not well written code! so however i'd like to use another os. Moreover the emac device is tested only with such driver so i expect some pb during porting, so excuse in advance if some pb could arise.

Have a good day
Salvatore

--- Mer 29/10/08, Hollis Blanchard <[email protected]> ha scritto:

Quoted 20 lines

Da: Hollis Blanchard <[email protected]>
Oggetto: Re: [Qemu-devel] TCG on PowerPC arch
A: [email protected]
Cc: [email protected]
Data: Mercoledì 29 ottobre 2008, 16:15

Quoted 2 lines · Andreas Färber

How did you actually use and test your eMac emulation?

I assume you did not

Quoted 1 line

use a PReP Linux kernel for that? If you could provide

some details, that

Quoted 1 line

might help with testing the TCG conversion too.

(Just in case there's any confusion, EMAC is the name for the ethernet
controller on IBM's 405- and 440-based SoCs, not to be confused with
Apple's eMac product.)

Quoted 7 lines

Salvatore, did you use a 405 Linux kernel with the EMAC driver to test
this patch? If so, how exactly did you boot? What did you do for
firmware?

-Hollis

Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo

#11 lore raw

Hi,

thanks for trustworth toward me!

As i said in previous email, i decide to test u-boot emac driver. Actually:
- uboot cross compile and make process generates an image for walnut board
- qemu load such image but stop executing during board init

Next step i'm doing is to build a new board in u-boot (possibly linking the configuration of qemu machine with u-boot, but with low priority) and verify emac/mal layer.

The link you give is about 'Sycamore' board, also support by u-boot. Thanks for this info, i'll try the most 'simple' board to give feedback ASAP.

Have a good day

--- Ven 31/10/08, Hollis Blanchard <[email protected]> ha scritto:

Quoted 100 lines

Da: Hollis Blanchard <[email protected]>
Oggetto: Re: [Qemu-devel] TCG on PowerPC arch
A: [email protected]
Cc: [email protected]
Data: Venerdì 31 ottobre 2008, 15:44
To summarize, you're saying that the only way you're able to test the
EMAC patch is with a custom firmware you can't make public? Obviously
that's not ideal, but I think some EMAC emulation is better than none
at all, so IMHO that shouldn't necessarily block your patch.

The problem I had when trying to test qemu's 405 emulation was that
Linux needed firmware to load it, and no 405 firmware is distributed
with qemu. At the time, Jocelyn claimed we could download a binary
uboot image from AMCC, but that didn't actually work. (I think we
ended up using
http://www.amcc.com/Embedded/Downloads/download.html?item=129&start=y).
This was probably a year ago, so details are fuzzy now.

However, if you have access to a 440 board, you could use KVM
(http://kvm.qumranet.com/kvmwiki/PowerPc) to boot a guest kernel with
the EMAC driver and test that way. Qemu's instruction emulation
doesn't support 440, but KVM implements all the instruction emulation
itself and does run on 440.

Anyways, I definitely think it's worthwhile to update your patch to current SVN.

-Hollis

Quoted 3 lines · Salvatore Lionetti

Hi Hollis,

please excuse me, but i can't release my firmware

(based on OSE)

Quoted 2 lines

If you agree, i'd like to
- catch svn status to test emac for my 405 based

board, custom fw

Quoted 1 line

- compile a linux kernel for ppc405 cpu, with emac

driver

Quoted 3 lines

(i've trying eCos but no emac driver :(0)

For first step actually have some pb with proxy

script.

Quoted 1 line

The second one is not strictly depend on me, but

'm very glad if anybody do it. Moreover emac driver in our custom firmware only used reversed mii, and is not well written code! so however i'd like to use another os.

Quoted 1 line

Moreover the emac device is tested only with such

driver so i expect some pb during porting, so excuse in advance if some pb could arise.

Quoted 5 lines

Have a good day
Salvatore

--- Mer 29/10/08, Hollis Blanchard

<[email protected]> ha scritto:

Quoted 10 lines
Quoted 10 lines

Da: Hollis Blanchard <[email protected]>
Oggetto: Re: [Qemu-devel] TCG on PowerPC arch
A: [email protected]
Cc: [email protected]
Data: Mercoledì 29 ottobre 2008, 16:15

Quoted 2 lines · Andreas Färber

How did you actually use and test your eMac

emulation?

Quoted 2 lines
Quoted 2 lines

I assume you did not

Quoted 1 line

use a PReP Linux kernel for that? If you

could provide

Quoted 2 lines
Quoted 2 lines

some details, that

Quoted 1 line

might help with testing the TCG conversion

too.

Quoted 2 lines
Quoted 2 lines

(Just in case there's any confusion, EMAC is

the name

Quoted 2 lines
Quoted 2 lines

for the ethernet
controller on IBM's 405- and 440-based SoCs,

not to be

Quoted 4 lines
Quoted 4 lines

confused with
Apple's eMac product.)

Salvatore, did you use a 405 Linux kernel with the

EMAC

Quoted 2 lines
Quoted 2 lines

driver to test
this patch? If so, how exactly did you boot? What

did you

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

do for
firmware?

-Hollis

Unisciti alla community di Io fotografo e video,

il nuovo corso di fotografia di Gazzetta dello sport:

Quoted 2 lines

http://www.flickr.com/groups/iofotografoevideo

Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo